Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift UIApplication.setStatusBarStyle Doesn't work

Here's my implementation in a subclass of UIViewController:

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: false)
}

I tried putting it in AppDelegate initialisation code (using the passed in UIApplication instance), however the status bar is still black..

Is this a bug with iOS 8 or am I doing it wrong?

Note: I may be breaking someone's law's here by discussing ios 8.. Its a general problem that, when compiled doesn't work for ios 7 either.

Update: Still doesn't work, even with value in Info.plist and code in - didFinishLaunchingWithOptions Nope still doesn't work

like image 405
Matej Avatar asked Jul 08 '14 02:07

Matej


2 Answers

You really should implement preferredStatusBarStyle on your view controller(s):

override func preferredStatusBarStyle() -> UIStatusBarStyle {
    return .LightContent
}
like image 200
drewag Avatar answered Nov 01 '22 04:11

drewag


  1. Go to Info.plist file
  2. Hover on one of those lines and a (+) and (-) button will show up.
  3. Click the plus button to add new key Type in start with capital V and automatically the first choice will be View controller-based status bar appearance.
  4. Add that as the KEY.
  5. Set the VALUE to "NO"
  6. Go to you AppDelegate.swift
  7. Add the following code, inside the method
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject:AnyObject]?) -> Bool {
    application.setStatusBarStyle(UIStatusBarStyle.LightContent, animated: false)

    return true
}
  1. DONE! Run your app and your status bar is now WHITE!
like image 43
nycdanie Avatar answered Nov 01 '22 02:11

nycdanie