Created
June 29, 2015 17:39
-
-
Save gabro/b578fcd3f304e4423c7e to your computer and use it in GitHub Desktop.
colored status bar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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