Search code examples
iosswiftuinavigationcontrollerstatusbar

ViewControllerBased, Light content Status bar with Transparent Navigation Controller


In my application i want to add light content status bar with translucent,transparent navigation bar. But when i make my navigation bar transparent it adjust itself with Black status bar content color. Navigation controller is compulsory in my case because table header needs to be stuck to it with plain mode. Any help from you will be appreciated.

enter image description here I have used this code for making my navigation bar transparent.

self.navigationBar.translucent = true
self.navigationBar.shadowImage = UIImage()
self.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)

I tried to make status bar appearance light by setting the bar style of navigation controller like

self.navigationController!.navigationBar.barStyle = .Black/.Default

But, still i am facing the same


Solution

  • if you want set for full application

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    
            UIApplication.sharedApplication().statusBarStyle = .LightContent
    
            return true
        }
    

    if you want to update only for view controller

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
    
        UIApplication.sharedApplication().statusBarStyle = .LightContent
    
    }
    

    For iOS 9

    set for full application

    Just open info.plist and set UIViewControllerBasedStatusBarAppearance to false

    Now update in AppDelegate's didFinishLaunchingWithOptions method


    only for view controller

    set View controller-based status bar appearance to YES

    override below in your view controller

    override func preferredStatusBarStyle() -> UIStatusBarStyle 
    { return UIStatusBarStyle.LightContent }