I want to change background color of status bar on iOS 7, and I\'m using this code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOp
Here's a swift solution that uses auto layout, If your application is in portrait or landscape the bar will be the correct width. It's added to the navigation bar view as a subview hence it's offset by -20. You could add it to your navigationbar's parent view, and then the offset is not required. This example will also set the colour to be the same as the navigation bar.
Hope that helps :)
// Add colored opaque view behind the status bar view
let statusBarView = UIView()
statusBarView.backgroundColor = navigationBar.backgroundColor
statusBarView.translatesAutoresizingMaskIntoConstraints = false
navigationBar.addSubview(statusBarView)
let views = ["statusBarView": statusBarView]
let hConstraint = "H:|-0-[statusBarView]-0-|"
let vConstraint = "V:|-(-20)-[statusBarView(20)]"
var allConstraints = NSLayoutConstraint.constraintsWithVisualFormat(hConstraint,
options: [], metrics: nil, views: views)
allConstraints += NSLayoutConstraint.constraintsWithVisualFormat(vConstraint,
options: [], metrics: nil, views: views)
NSLayoutConstraint.activateConstraints(allConstraints)