https://nickymarino.com/public/assets/2020/optimizing-virgo/example_11.png
For some iOS apps, it may be helpful to change the color of the status bar at the top of the screen. For example, if I have a dark background, the default status bar style is hard to read:
To change the appearance of the status bar within a view controller, first add “View controller-based status bar appearance” as an item to your Info.plist
with a value of YES
:
Then in any view controller, you override the preferredStatusBarStyle
property:
override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent }
And if you ever need to update the status bar color, call setNeedsStatusBarAppearanceUpdate()
. Now the full view controller looks like this:
import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, // typically from a nib. setNeedsStatusBarAppearanceUpdate() } override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent } }
Running this view controller, we get a light status bar!
Top comments (0)