I have a web view that I want to fill the full screen of a iDevice. I placed it in the center of the view set to be center and flush with the edge of the container. However when I load the app, the view is larger than the emulated iPhone it is running in. I have done some searching and some suggest auto layout, which is already supposed to be centering the view. Another thing I found was to set the size though code.
self.webView.frame = self.view.bounds
I even changed the app from a universal app to just iPhone, with no effect on the layout.
Full source:
class ViewController: UIViewController {
@IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.webView.frame = self.view.bounds
webView.frame = self.view.bounds
var uri = NSURL(string:"http://google.com")
var req = NSURLRequest(URL: uri)
webView.loadRequest(req)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
A view that embeds web content in your app.
A WKWebView object is a platform-native view that you use to incorporate web content seamlessly into your app's UI. A web view supports a full web-browsing experience, and presents HTML, CSS, and JavaScript content alongside your app's native views.
Android WebView is a system component for the Android operating system (OS) that allows Android apps to display content from the web directly inside an application. Android is powered by Chrome. Mobile Safari UIWebView.
To clear old contents of webview With UIWebView you would use UIWebViewDelegate 's - webViewDidFinishLoad: .
Set the scaling to fit the view bounds. Try this:
self.webView.frame = self.view.bounds
self.webView.scalesPageToFit = true
Hope this helps.. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With