UIWebView content not scaling between different iP

2019-02-11 05:23发布

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.

5条回答
smile是对你的礼貌
2楼-- · 2019-02-11 05:57

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.

查看更多
叛逆
3楼-- · 2019-02-11 05:59

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.

查看更多
小情绪 Triste *
4楼-- · 2019-02-11 06:00

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).

enter image description here

Try selecting the bounds as per your requirements. This will surely solve your problem.

查看更多
一纸荒年 Trace。
5楼-- · 2019-02-11 06:02

What helped me is a creation of 4 constraints:

enter image description here

查看更多
SAY GOODBYE
6楼-- · 2019-02-11 06:05

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

查看更多
登录 后发表回答