Reputation: 1712
Hopefully, third time lucky:
Simply trying to get content to appear below Navigation Bar and above Tab Bar (with none of it, appears below either).
I have tried pretty much everything, to no avail.
With the following code inside rootController where I'm simply trying to have a view (red border to help show if it's working):
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
UIView *view1 = [[UIView alloc] initWithFrame:self.view.frame];
view1.layer.borderColor = [UIColor redColor].CGColor;
view1.layer.borderWidth = 2.0f;
[self.view addSubview:view1];
}
and the setup as being:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
TSTFirstViewController *rootController = [[TSTFirstViewController alloc] init];
rootController.title = @"Hello World";
UINavigationController *firstRootController = [[UINavigationController alloc] initWithRootViewController:rootController];
NSArray *viewControllers = @[firstRootController];
UITabBarController *tabBar = [[UITabBarController alloc] init];
tabBar.viewControllers = viewControllers;
tabBar.tabBar.barStyle = UIBarStyleBlack;
tabBar.tabBar.translucent = NO;
[self.window setRootViewController:tabBar];
[self.window makeKeyAndVisible];
return YES;
}
I get:
If I add two lines to my AppDelegate
:
firstRootController.navigationBar.translucent = NO;
firstRootController.navigationBar.barStyle = UIBarStyleBlack;
It all gets very messy:
The red border shifts down, the bottom border disappears below the tab bar. And a large whitespace appears.
If I remove the translucency lines, and add:
self.edgesForExtendedLayout = UIRectEdgeNone;
into the view controller, I get:
Translucent bars, red border in correct place under the Navigation bar, but bottom border underneath tabBar.
I believe I've tried all combinations, and all ideas.
Can anyone please tell me how to get the content to fit underneath the Navigation Bar, above the Tab Bar without using Interface Builder.
Thanks in advance.
Upvotes: 0
Views: 508
Reputation: 5667
Yes, here is your solution.
When you are using self.edgesForExtendedLayout = UIRectEdgeNone;
kindly consider three more things in iOS 7 as
NavigationBar
.Status Bar
(Time, network, battery display on top)TabBar
as well.So your implementation should subtract the height of navigation bar, status bar & tabbar from the actual view height.
UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height-self.navigationController.navigationBar.frame.size.height-self.navigationController.tabBarController.tabBar.frame.size.height-[UIApplication sharedApplication].statusBarFrame.size.height)];
view1.layer.borderColor = [UIColor redColor].CGColor;
view1.layer.borderWidth = 2.0f;
[self.view addSubview:view1];
Here is an attached screen using this code.
I hope that helps.
Upvotes: 2