Swift How to Design Uiwebview Auto Resize Full Screen in Story Board

Swift how to design UIWebView Auto resize full screen in Story Board

In ViewDidLoad and when you use autolayout, the frame is not yet calculated.
So, place your code in viewDidLayoutSubviews or in viewDidAppear, and that should fix the bug.

You can also fix that, only by adding constraints in your interface builder (do not forget to remove your code in viewDidLoad) :

Sample Image

UIWebview full screen size

One cheap thing to do would be to set the frame of the webview in overriding - (void)viewDidLayoutSubviews

- (void)viewDidLayoutSubviews {
webView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
}

the advantage of doing it here, is that the size and orientation of the view has already been determined here, and you can get an accurate measurement.

How to full screen layout to a view in Swift?

You question is very vague. Maybe you messed up with your constraints? Try setting the constricts to the size of the screen instead of a specific height and width. make sure each thing is set to 0

Make sure each thing is set to 0

How do I make a UIWebView's content adjust to the iPhone screen size?

The statement

webView.scalesPageToFit = YES;

should size the web page to fit the size of the UIWebView. The user then has the option to zoom in and out of the page. Your problem might be because the webview is not located properly. If your view controller's view fits the screen entirely, add this to your code.

webView.frame=self.view.bounds;

UiWebView display in fullscreen

Your UIWebView already constrained to superView but myWebView's UIWebBrowserView shows under the safeArea.
By the way UIWebView was deprecated, please check the link below.

Debug View Hierarchy

Just change the UIWebView to WKWebView

  • Import WebKit
import WebKit

  • Initialize it

These Italian comments from OP's github repo so knowingly adding them here

//Definizione della UIWebView
var myWebView = WKWebView()

  • Change loadRequest lines to
myWebView.load(request)

  • In viewDidLoad
myWebView = WKWebView(frame: CGRect(x: 0, y: 0,
width: view.frame.width,
height: view.frame.height))

And run!


BONUS

UIWebView is deprecated -> Apple Docs

WKWebView documentation -> Apple Docs

WKWebView usage ->Hackingwithswift



Related Topics



Leave a reply



Submit