Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS8: How do I make statusBar opaque after navigationBar is hidden using hidesBarsOnSwipe?

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.

like image 443
CKIMNJ Avatar asked Jan 23 '15 22:01

CKIMNJ


1 Answers

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)
}
like image 123
Hans Brende Avatar answered Sep 21 '22 17:09

Hans Brende