OuSS
OuSS

Reputation: 1055

Same color for StatusBar and NavigationBar iOS

I added navigationBar manualy from controls enter image description here

How to make StatusBar Backgroud color = same as navigationBar

enter image description here

Upvotes: 1

Views: 2645

Answers (1)

Joe
Joe

Reputation: 8986

Try this code: Tested in Swift 3

@IBOutlet weak var navBar: UINavigationBar!

override func viewDidLoad() {
    super.viewDidLoad()

    navBar.barTintColor = UIColor.black // Set any colour 
    navBar.isTranslucent = false

    navBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.white, NSFontAttributeName:UIFont(name:"HelveticaNeue", size: 16)!]

    let barView = UIView(frame: CGRect(x:0, y:0, width:view.frame.width, height:UIApplication.shared.statusBarFrame.height))
    barView.backgroundColor = UIColor.black
    view.addSubview(barView)
}

override var preferredStatusBarStyle: UIStatusBarStyle {

    return .lightContent
}

Updated to clear down voters

enter image description here

Upvotes: 4

Related Questions