How to prevent UINavigationBar from covering top of view in iOS 7?
Solution 1:
Set the navigation bar's translucent property to NO:
self.navigationController.navigationBar.translucent = NO;
This will fix the view from being framed underneath the navigation bar and status bar.
If you have to show and hide the navigation bar, then use
if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone; // iOS 7 specific
in your viewDidLoad
method.
Solution 2:
In iOS 7
by defaults all Controller translucent property value is YES, so you set translucent property NO for this issue.
self.navController.navigationBar.translucent = NO;
Solution 3:
You can disable the "Extend edges" in Attribute inspector of View Controller of this screen (as shown in below image) :
Solution 4:
This works for swift as well on iOS 8.1
navigationController?.navigationBar.translucent = false
Solution 5:
If you want to keep the translucency on your navigationBar
, at the end of your viewDidLoad
or in your viewWillAppear
add this line of code:
[self.view sendSubviewToBack:self.tableView]
Somehow if your scrollView
subclass (UITableView
, UICollectionView
, etc.) is at index
0 in your current view subviews
, it will automatically adjust the insets according to your navigationBar
. And it shouldn't affect your UI in versions prior to iOS7 either.
EDIT
If you initialize your UITableView
programmatically, then it is best to add it to the view using this [self.view insertSubview:self.tableView atIndex:0];