Swift UIApplication.setStatusBarStyle Doesn't work

走远了吗. 提交于 2019-12-10 17:22:14

问题


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


回答1:


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

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



回答2:


  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!


来源:https://stackoverflow.com/questions/24622960/swift-uiapplication-setstatusbarstyle-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!