I have a UIwebview that I want to fill the screen between the navigation bar at the top and the tab bar at the bottom. My web view is being defined programmatically and I was initializing it with a frame as below.
I have been able to get the desired behavior by hard coding in some values, but I have seen that this does not work across all devices. Specifically, it seems that different OS's might consider (0,0) as different points on the screen (the top left corner of the screen for some, and the top left most corner under the nav bar for others).
My question is, how do I set the web view position and size to fill the screen across all devices? And can anyone explain why this doesn't behave as I think it ought to?
//iphone 5s running iOS 8
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight+20)];
//iphone 5 running iOS 7
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 64, screenWidth, screenHeight-93)];
//what i thought would work for all, but doesnt fill the height of the screen...
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];
Related
I'd like to achieve the same effect as in Safari where the navigation bar changes slightly in color to reflect the web page that passes through while scrolling.
The 6 years old method that used to work with UIWebView is to simply include these two lines of code:
webView.scrollView.contentInset = UIEdgeInsetsMake(44.0, 0.0, 0.0, 0.0);
webView.scrollView.scrollIndicatorInsets = _webView.scrollView.contentInset;
Since WKWebView the edge insets work much like content offset. It displays correctly initially but when you scroll the web page moves underneath the UINavigationBar/UIVisualEffectView making in it impossible to reach the top bar of websites that adjust accordingly, like at apple.com
Is there any other way?
The answers below are 6 years old and obsolete.
You need to move the web view under the navigation bar, and then set the web view's contentInset, like so:
navBar.frame = CGRectMake(0, 0, self.view.bounds.size.width, 44);
webView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
webView.scrollView.contentInset = UIEdgeInsetsMake(44, 0, 0, 0);
webView.scrollView.scrollIndicatorInsets = webView.scrollView.contentInset;
Go to you app setting in xcode and in Status Bar Style click the drop down and select "Light".
These should apply in all your app
I'm creating a UIViewControl with this this website. I finished it, but when I load my image, the bottom of my image gets cut off. I'm sure the dimensions of the image are correct, besides the UIImageView is stretched throughout whole screen.
Since the whole code is on the site, I won't be adding anything here, except for one line I changed.
I changed
self.pageViewController.view.frame =
CGRectMake(0, 0, self.view.frame.size.width,
self.view.frame.size.height - 30);
to
self.pageViewController.view.frame =
CGRectMake(0, 0, self.view.frame.size.width,
self.view.frame.size.height);
The gap got smaller but is still there. It looks like this
Thank you.
Have you taken into account the height of the status bar at the top of the phone?
I think that in iOS 7 the status bar overlaps the content by default, you might have to slide the content down a bit.
I´v read the posts regarding this issue but found nothing to work, I think it must be since I am using a toolbar and have the View Controller embedded in a container view. The status bar always overlaps. No matter if I try to replace the toolbar or set different settings in IB. It also seems that since it´s inside a container view, setting the inferred option does not work. I even tried putting two toolbars on top, but only this one shows.
The status bar in iOS 7 is transparent, so if you want to have a look similar to that of iOS6, create a view of 20 pixels and add it inside your "container" view...
UIView *statusBarView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, 320, 20)];
statusBarView.backgroundColor = [UIColor blackColor];
[containerViewController.view addSubview:statusBarView];
Then set the frame of your "contained" ViewController accordingly
containedViewController.frame = CGRectMake(0, 20, 320, itsCurrentHeight - 20);
This way the status bar should not overlap with your content anymore
I am creating an iPad app using the master-detail template available in Xcode 4.3. My master tableview is acting as a navigation menu for the detail view and the menu items will be fixed. So I basically don't exactly need the scrolling view, thus I have turned it off.
self.tableView.scrollEnabled = NO;
Now I have a requirement to display a footer like cell aligned at the bottom of master menu just like in Twitter iPad app. The cell should appear at the bottom in landscape as well as portrait modes. Can somebody give me some hints regarding how to implement this?
I read on some blogs about using a UIView and setting it to UITableView.tableFooterView, something like this...
// I'll have to do calculations of frame height/x/y for both orientations
// to make the view appear at bottom - IS THERE A SIMPLER WAY???
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 944, self.tableView.frame.size.width, 60)];
UILabel *logo = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 60)];
logo.text = #"This is the Footer.";
[footerView addSubview:logo];
self.tableView.tableFooterView = footerView;
After looking at the app, I don't think the "footer" is part of the table. It looks more like a small view under the table. So the table is set up so it will stretch vertically but it's height is locked above the bottom view. Maybe it would be better to use a UIViewController and a UIView for you Master View instead of a UITableViewController. Then put your UITableView in the UIView and put your footer below it. Then configure the UIViewController to work with the UITableView as it did before.
Hope this helps.
I have an app that has both navigationbar and toolbar on display with various buttons...
I have an imageview that will act as a help overlay (like you see in many apps these days) that is semi transparent with arrows pointing to the buttons on the bars plus actual view content.
First attempt displays the imageview in the view area but leaving the bars in place...not good!
So next attempt I have included the bars as part of the imageview and add this to take up the entire screen, so far so good. I then hide the bars but oh no.....the view moves up 44 pixels (as expected)
Problem is no matter what I do I cannot get the view to move down the 44 pixels?
So the imageview displays the bars giving the illusion the overlay (imageview) is on top, but the view in between is out of whack!
Does anyone know how to resolve this?
UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(20, 0, 750, 1024)];
iv.userInteractionEnabled = YES;
iv.image = [UIImage imageNamed:#"myimage.png"];
UIWindow *window = self.view.window;
[window addSubview:iv];