Reputation: 953
In my app I am using UITabBarController. This is how it looks like in the IB:
TabBarController is used as a rootViewController of the window.
Here is my code where I fill the TabBarController with views:
tabBar = [[UITabBarController alloc]init];
myViewController1 = [[MyViewController1 alloc] initWithNibName:@"View1" bundle:nil];
myViewController2 = [[MyViewController2 alloc] initWithNibName:@"View2" bundle:nil];
myViewController3 = [[MyViewController3 alloc] initWithNibName:@"View3" bundle:nil];
tabBar.viewControllers = [NSArray arrayWithObjects: myViewController1, myViewController2, myViewController3, nil];
[self.view addSubview:tabBar.view];
If some view is shown inside the TabBarController, it is under TabBar (height of this view is red line) - so if I have some TableView, I can't see last one or two rows. How can I achieve to show views inside TabBarController (like green rectangle) - not under tab bar?
I thought that it could be done automatically that if I show something if I am using UITabBarController, it is shown inside not under.
Upvotes: 3
Views: 2355
Reputation: 860
This worked for me
class TabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
// this will force child controller's view to be above Tab Bar
tabBar.isTranslucent = false
}
Upvotes: 1
Reputation: 4751
Since iOS7 most of the navigational items (including tab bar) are translucent. With that approach the user could see, for example, scrolling cells in UITableView.
There are two ways to deal with your issue:
if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;
But from my point of view the preferable way is too use AutoLayout and
You could do that programmatically:
[view setTranslatesAutoresizingMaskIntoConstraints: NO];
id topGuide = myViewController.topLayoutGuide;
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings (view, topGuide);
[myViewController.view addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat: @"V:[topGuide]-[view]"
options: 0
metrics: nil
views: viewsDictionary]
];
Or with storyboard:
Upvotes: 3