Skip to content

Instantly share code, notes, and snippets.

@gabro
Created June 29, 2015 17:39
Show Gist options
  • Save gabro/b578fcd3f304e4423c7e to your computer and use it in GitHub Desktop.
Save gabro/b578fcd3f304e4423c7e to your computer and use it in GitHub Desktop.
colored status bar
// let's create our status bar background view
let statusBar = UIView()
// set the navigation bar color to white (assuming `navController` is our `UINavigationController`)
navController.navigationBar.barTintColor = UIColor.whiteColor()
// turn off the autoresizing mask, since we're using autolayout
statusBarBg.setTranslatesAutoresizingMaskIntoConstraints(false)
// set a background color for the status bar
statusBar.backgroundColor = UIColor.blueColor()
// add our view to the nav controller view
navController.view.addSubview(statusBar)
// use autolayout to position the status bar
let views = ["statusBar": statusBar]
let hLayout = NSLayoutConstraint.constraintsWithVisualFormat("H:|[statusBar]|", options: .allZeros, metrics: nil, views: views)
let vLayout = NSLayoutConstraint.constraintsWithVisualFormat("V:|[statusBar(==20)]", options: .allZeros, metrics: nil, views: views)
navController.view.addConstraints(hLayout)
navController.view.addConstraints(vLayout)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment