Reputation: 14944
I'm trying to add a UIWebView inside a clean UIViewController which in my Storyboard is embedded in a Navigation Controller:
UIWebView *webView =[[UIWebView alloc] initWithFrame:self.view.bounds)];
webView.delegate = self;
[self.view addSubview:webView];
The problem is, that the self.view.bounds.size.height is 460, which seems to be the height of the entire view including the navigation bar. I could subtract the value of self.view.frame.origin.y which is 20 and get the desired hight of 440, but are there a more common way to do this?
EDIT
Please take a look at my small code example here: http://uploads.demaweb.dk/WebViewTest.zip
When you scroll down to the bottom of the UIWebView, the last part of the web site is not shown, as the webView is to high.
![enter image description here][1]
Upvotes: 3
Views: 5141
Reputation: 11539
I haven't found a better solution other than using topLayoutGuide
(and optionally bottomLayoutGuide
).
That is, adding your view to the controller's self.view
and setting these constraints:
"H:|[view]|"
"V:[top][view][bottom]"
Where top
is self.topLayoutGuide
and bottom
is self.bottomLayoutGuide
.
As an example, see the configureViewController:fillWithSubView:
method in AutolayoutHelper.
Upvotes: 0
Reputation: 14944
Solution
Setting the autoresizingMask
in the UIWebView solved my problem:
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
Upvotes: 2
Reputation: 29767
Default height is 480, 460 - height without status bar. 44px - height of navigation bar (you can access to height since it's a UIView - navBar.frame.size.height). So, your view height is 480-20-44 = 416. And you need to subtract from self.view.frame.size.height
, not origin.y
Upvotes: 0
Reputation: 80271
Don't worry about it. The navigation controller takes care of resizing the view
of the view controller under its jurisdiction. You would only override this view's frame if you would like it to be e.g. smaller to fit other subviews onto its superview.
Upvotes: 0