iOS 7: UITableView shows under status bar
For anyone interested in replicating this, simply follow these steps:
- Create a new iOS project
- Open the main storyboard and delete the default/initial
UIViewController
- Drag out a new
UITableViewController
from the Object Library - Set it as the initial view controller
- Feed the table some test data
If you follow the above steps, when you run the app, you will see that nothing, including tweaking Xcode's checkboxes to "Extend Edges Under {Top, Bottom, Opaque} Bars" works to stop the first row from appearing under the status bar, nor can you address this programmatically.
E.g. In the above scenario, the following will have no effect:
// These do not work
self.edgesForExtendedLayout=UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars=NO;
self.automaticallyAdjustsScrollViewInsets=NO;
This issue can be very frustrating, and I believe it is a bug on Apple's end, especially because it shows up in their own pre-wired UITableViewController
from the object library.
I disagree with everyone who is trying to solve this by using any form of "Magic Numbers" e.g. "use a delta of 20px". This kind of tightly coupled programming is definitely not what Apple wants us to do here.
I have discovered two solutions to this problem:
Preserving the
UITableViewController
's scene:
If you would like to keep theUITableViewController
in the storyboard, without manually placing it into another view, you can embed theUITableViewController
in aUINavigationController
(Editor > Embed In > Navigation Controller) and uncheck "Shows Navigation Bar" in the inspector. This solves the issue with no extra tweaking needed, and it also preserves yourUITableViewController
's scene in the storyboard.Using AutoLayout and embedding the
UITableView
into another view (I believe this is how Apple wants us to do this):
Create an emptyUIViewController
and drag yourUITableView
in it. Then, Ctrl-drag from yourUITableView
towards the status bar. As the mouse gets to the bottom of the status bar, you will see an Autolayout bubble that says "Top Layout Guide". Release the mouse and choose "Vertical Spacing". That will tell the layout system to place it right below the status bar.
I have tested both ways on an empty application and they both work. You may need to do some extra tweaking to make them work for your project.
Display tableView under status bar
Add the code in this method- -viewDidLayoutSubview()
[self.tableView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];
TableViewController scrolls under status bar
Solved it!
The problem was the code I wrote to hide the navigation bar hairline (the 1px line under the bar).
Commenting the code make everything work fine.
UIViewController and tableView below status Bar
you can hide status bar with this code in your view controller
override var prefersStatusBarHidden: Bool {
return true
}- If you don't want to hide status bar you can set your table view's top constraint equal to super view's top
This worked for me
Orange view is under status bar
How do I make my iOS7 UITableViewController NOT appear under the top status bar?
In case anyone misses the How the story ended section at the end of the (now long) question, the short answer is: Use a simple UIViewController with a TableView, instead of a TableViewController if you want to achieve the stated goal.
Changing only the body colour of UITableView or changing only the status bar colour
You can apply background color to status bar like following
UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
statusBar.backgroundColor = [UIColor redColor];
}
Using the above code in AppDelegate didFinishLaunchingWithOptions
method would change the status bar background color of entire app. If you want to change the background color to specific view controllers, then you should follow the @Lion's
approach.
Hope this helps.
Status Bar appearing over the top of Tableview
this is status bar issue.
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)
{
self.edgesForExtendedLayout=NO;
}
or
In your Appdelegate
if (SYSTEM_VERSION_LESS_THAN(@"7.0")) {
self.window=[[[UIApplication sharedApplication]delegate] window];
self.window.frame = CGRectMake(0,-20,self.window.frame.size.width,self.window.frame.size.height+20);
}
ios-7-uitableview-shows-under-status-bar
Related Topics
Sending an Http Post Request on Ios
How to Deploy an Iphone Application from Xcode to a Real Iphone Device
How to Force View Controller Orientation in iOS 8
Firebase Query - Find Item With Child That Contains String
How to Check When a Uitextfield Changes
Seeing Black Bars At the Top and Bottom of the Iphone X Simulator
Ios 8 Uitableview Separator Inset 0 Not Working
Get to Uiviewcontroller from Uiview
Attempt to Set a Non-Property-List Object as an Nsuserdefaults
Add Uipickerview & a Button in Action Sheet - How
Getting and Setting Cursor Position of Uitextfield and Uitextview in Swift
How to Easily Resize/Optimize an Image Size With Ios
How to Create a Basic Uibutton Programmatically
Why It Shows "Ld: Framework Not Found Bolts"
Redirect to Application If Installed, Otherwise to App Store