Reputation: 10834
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.
}
}
Upvotes: 7
Views: 15159
Reputation: 71852
If you don't want to set this programetically then One way to do this is add this 4 constraint to your webView this way:
This works for me.
Upvotes: 1
Reputation: 11197
Set the scaling to fit the view bounds. Try this:
self.webView.frame = self.view.bounds
self.webView.scalesPageToFit = true
Hope this helps.. :)
Upvotes: 10