UIWebView content not scaling between different iPhone sizes - ios

So I am working on an iOS app that uses the UIWebView to serve HTML content. Why UIWebView and not WKWebView? well I want this app to work on iOS7 and above. I have just updated my Xcode to Xcode 6.1 and I cannot get my webView to scale to fit the available screen space when changing from the 4 inch screen size to 4.7 and above.
What I am after is to have my app look consistent on all iPhone screen sizes of 4 inch and above as all my HTML5 code that is displayed on the web view is.
In my Attributes inspector I have set the size to iPhone 4-inch and you can see what the app looks like in simulators for iPhones of size 4-inch and 4.7-inch respectively in the link below,
http://imgur.com/gallery/tz7LG/new
How do I get this to scale up appropriately on iPhone screens of different sizes?
fyi, I have set the Scale page to Fit to true for my webView. I am building this app using Swift.

To solve such issue,
1) Uncheck "Use Auto layout" and also disable size classes.
2) Open the size inspector to use Autoresizing as directed in the image below on the desired element (in your case its UIWebView).
Try selecting the bounds as per your requirements.
This will surely solve your problem.

Do check that you haven't coded the dimensions in the .m file.
The answer by Piyush Mathur is simple and seems usable in the given case.
But if the requirements are complex then you need to "Use Auto Layout".
Also make sure that you have set all the needed constraints of the Web-View.
The Introduction to Auto-Layout gives an idea to set constraints to a component which will also give an idea to stretch component (Web-view in your case) based on the device screen size.

You could use Xcode's auto layout tool, which will automatically resize the UIWebView according to the device.

I think the best practice is to untick "constraint to margin" when you add the constraints.
Here are three steps: 1. clear all constraints; 2. add the constraints back in and untick "constrain to margin"; 3. set all four constraints to 0.
Or if you are familiar with the Xcode, this can be done in one step.

What helped me is a creation of 4 constraints:

Related

Support for ipad size in Swift 4

I have successfully completed iPhone development using Auto Layout.
Thanks to Auto Layout, UI is displayed normally on all iPhones.
However, if I run it on the iPad, the UI will not break, but the screen will be small.
I have no idea what to do to support iPad size in storyboard or build settings.
If I want my app to respond to iPad size, what method should I use specifically?
I am using Xcode 10 and Swift 4.
Select your project in Xcode, then use the General tab. It's under the sections on Identity and Signing.
1) Select constraint that you need to update for iPad.
2) Click on + sign to the left of "Constant" value
3) Select Width and Height - Regular which conforms to iPad in portrait and landscape orientation and set your values
4) Now when your select iPad second value will be applied to your layout.
Also you can vary font for different devices:
Every settings that has + sign on the left can be vary for different screen sizes and orientations. You can read great tutorial about variations on
Ray Wenderlich web site
You want to use "Vary for Traits" when editing the storyboard. You can then adjust the layout for the different sizes of iPad.
As stated in the comments above, check your deployment info also to ensure it's set to "Universal".

Supporting all iphone sizes

I'm trying to create a iOS app, but I'm stuck on the layout.
I created the home view, but now I see that it's not shown in the right way in the 4S simulator.
I tried with size classes, but it looks like 4S and 6, for example, are in the same size class, and so I can't set a different dimension for views.
My goal is to support all devices, also iPads. Can someone please tell me how to do it?
Size classes mostly used for separation between ipad, apple watch and landscape modes.In potrait mode iphone 4 to iphone 6 all phone device sizes are in same class(regular height and compact width).Autolayout has many different constraints to help you to fit interfaces in same class.You should consider horizontaly/verticaly align, equal width and aspect ratio constraints.They are so flexible for smaller size changes and help you to design adaptive layout.
You should use "Reset to Suggested Constraints" for all views in your View controller. You can also check the simulated metrics for all devices without compiling the the code.
For 4s and 6 by default the size is Inferred. You should try resetting the constraints to check this for iPad as well.
I am just sharing an idea
Option1:
I think You can try adaptive Layouts and in file inspector->simulated Metrics->size-> Inferred. It works in all devices it supports both landscape and Portrait.
Option2: Go for Visual layouts they are easy to understand and they work perfect in all modes of Portrait.
I am think that you use code Instead design in main.storyboard !
for ex: create button with code
(and use Ratio in your code)
by this way i create small app for iPhone & iPad
!

Universal iPhone Auto-Layout

I decided to make an iPhone-only application but since there are so many different sizes of an iPhone screen I have no choice but use Auto-Layouts. There is a grid which allows you to chose width and height of the layout so I decided to choose the "wCompact hRegular" one because it says "Any iPhone in Portrait" but every time that I run my application on iPhone 6 it uses the "wCompact hAny" layout which does not work right. So my questions are:
Is there any way to use ONLY wCompact hRegular layout?
Is there a way to not use Size Classes and just stretch 16:9 iPhone 5
version?
And if there is not, what is the best solution for my problem?
Thank you in advance!
Better you disable "Size Classes" and use "Auto Layout" instead. To do that 1. Select your storyboard file from your project navigator
2. In the file inspector under interface Builder Document check "Use Auto Layout".

Autolayout(xcode 6,swift)

In I phone 5s simulator its working fine! I have one label,one image view and one button.As you can click on the link and see the picture now so i tell you that I used my image view as a background and the label is in the middle and the button is in the lower middle so i want that to look same in all the devices. i don't know anything about constraints.I am using Xcode 6
https://drive.google.com/file/d/0B2z_d4wEKPEFLV9RNFVlR3A5SFppa0tJT2tiQkQwVVVVTDVz/view?usp=sharing
I suggest you to take a look at this youtube tutorial. I learned how to make the constrains by watching it. The tutorial teaches how to make the similar layout as you required.
Link: https://www.youtube.com/watch?v=RpMzEmF-xZM
Hope this is helpful~
Autolayout is the tool used to make UI look similar across all devices, you should try to learn it if you want to continue to develop IOS apps. The concepts are pretty basic and are used throughout other languages.
This tutorial is useful if you want to create the auto layout using storyboards.
This tutorial is useful if you are making the view programmatically. I tend to use code for auto layout but it is just a preference, storyboards is fairly simple so I would suggest that. If you are going to do it in code a is to forget setting the autoresizing mask into constraints to false. You have to set this property on all the views you want to use auto layout for.
view2.setTranslatesAutoresizingMaskIntoConstraints(false)
Background ImageView
Select Image ->Pin->Uncheck Constraints to margin-> select top,bottom,left,right.
Button
Select Button-> Pin->Uncheck Constraints to margin->select bottom,left,right,Height.
label
Select label->Align->Center horizontally and Center Vertically in Container.
Pin->Width,Height.
If it is working for iPhone 5 but not another layout then this is probably happening.
There are demensions in the centre of the lower tab bar of story boards
There are screen size settings in the story board and regular*regular is the only one that is universal to all orientations and sizes of the ios device. if you set constraints while viewing in regular by compact (landscape for 5.5 inch iPhone) then those constraints will only be apply to 5.5 inch iPhones in landscape and if you tried running on a smaller iPod it would be as if you never set the constraints. the constraints for the 5.5 inch iPhone would not apply to the small iPod
if constraints were made in compact by compact and you were viewing the story board in say regular by compact then you would get an error saying that things are misplace and will not appear in the same at runtime. view the storyboard in the same dimensions that you set the constraints and you should not have an issue.
There is an option to simulate the device you want to run on specifically in storyboard and it can be say only 5.5 inch iPhones or something, whatever device.
go to paul hegarty developing iOS apps with swift on iTunes you if you want to learn more. He is a good source.

Alignment issue when running simulator

I am trying to run a simple sample using a nib file and it looks like this
However when I run it in my simulator it looks like this
My question is why is the alignment of the simulator not correct ?
The elements should be close to the middle and the screen height should be longer. Any suggestions on how I could fix this ? I am using Xcode 6.2
Here are the things I tried so far :
1 ) I made sure that the alignment in my nib file is set to Auto Layout.
These are the details of my project. I am testing on an iphone 6 as my simulator.
Any suggestions on how I can fix this ?
You need to set Constrain in AutoLayout if u don't want to use auto-layout then u can unCheck it .. you can refer this tutorial http://www.raywenderlich.com/50317/beginning-auto-layout-tutorial-in-ios-7-part-1
You probably need to configure size classes for the class device that you use.
If your app is only for iphone, you can also disable size and keep size classes for iphone only.
Hint Use preview from: Assistant editor -> Automatic > Preview, you will be able to see a preview of the view with all device screen sizes

Resources