How to set Status Bar in iOS?

Setting the UIStatusBarStyle  is very simple in iOS. Below is how it looks like with lightContent Style and the Default Style.

Based on the app. UIView backgroundColor, you can set the way a status bar should appear.




There are two ways to achieve this. The first one being the recommended one since iOS 7. For this one would have to make changes in Info.plist.

1) In iOS 7 onwards, you can specify the bar style per view controller. For this the value for Key UIViewControllerBasedStatusBarAppearance in info.plist should be set to YES.




Now in your controller you should override a property preferredStatusBarStyle as coded below.



    override var preferredStatusBarStyle: UIStatusBarStyle {
        get{
            return .lightContent
        }

    }


Changing the return to .default will give you dark status bar style.


2) So, if you are planning to use the default method which API says its Deprecated, you need to UIViewControllerBasedStatusBarAppearance in info.plist should be set to NO. 

This way status bar is set for the entire app. and not per ViewController.

 


Comments

Popular posts from this blog

hitTest on iOS to identify the view being hit

CMTimeMakeWithSeconds explained

Custom Editing Control for UITableViewCell , like iPhone Mail Appliation