Sunday, 18 June 2017

Background color of status bar

UINavigationBar includes status bar which is of 20 points in height of UINavigationBar. Thus the actual default height of UINavigationBar is 44 point. 
When we change the background color of UINavigationBar, it includes the background color of status bar also. Thus by setting the background color of UINavigationBar with 

        UINavigationBar.appearance().barTintColor = UIColor.Red

will set the background color of navigation bar as well as status bar to red.

Thus to set the different background color of status bar other than navigation bar's tint color, you can use these line of code in your application at appropriate place:

        //change appearance of status bar
        
        UINavigationBar.appearance().clipsToBounds = true
        //get the status bar
        let statusBar: UIView? = UIApplication.shared.value(forKey: "statusBar") as? UIView
        //set background color
        statusBar?.backgroundColor = UIColor.white

No comments:

Post a Comment