11

I am building iOS8 app. On my tableview controller, I am using self.navigationController.hidesBarsOnSwipe = YES, to hide the navigationBar on swipe up gesture. It is working nicely, but my statusBar becomes transparent and shows the table content underneath.

On storyboard, Status Bar are Top Bar are set to "Inferred"

I want to: 1. Keep my status bar opaque 2. Maintain the same color as the navigationBar 3. Table content scrolls underneath the statusBar

Thank you.

CKIMNJ
  • 111
  • 1
  • 7
  • i think that there is no official solution for this at the moment. You have to implement this behavior by yourself. – Sebastian Boldt Mar 03 '15 at 15:06
  • possible duplicate of [How to prevent status bar from overlapping content with hidesBarsOnSwipe set on UINavigationController?](http://stackoverflow.com/questions/25870382/how-to-prevent-status-bar-from-overlapping-content-with-hidesbarsonswipe-set-on) – Michał Ciuba Mar 18 '15 at 20:13

3 Answers3

6

Here is a Swift solution:

First, change UITableViewController to UIViewController and add a tableView field. Then, implement your viewDidLoad method as follows:

override func viewDidLoad() {
    super.viewDidLoad()
    tableView.delegate = self
    tableView.dataSource = self
    tableView.frame = view.frame
    view.addSubview(tableView)

    let topBar = UIView(frame: UIApplication.sharedApplication().statusBarFrame)
    topBar.backgroundColor = myDesiredColor
    view.addSubview(topBar)
}
Hans Brende
  • 7,847
  • 4
  • 37
  • 44
  • Note: this is fragile. It is not set up to resize upon rotation (nor any other possible changes to the status bar dimensions). – Jamie Birch Sep 25 '19 at 21:04
0

You can add a constraint to the top layout, by this scrolling content will not appear below the status bar.

Santhosh
  • 103
  • 8
0

Make a custom View.

UIView * statusBarView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 20)];
statusBarView.backgroundColor=[UIColor whiteColor];
[self.view addSubview:statusBarView];