0

The target screenshot want

First,I have read those link

All of the links use those API of UIApplication

- setStatusBarStyle:animated:
- setStatusBarHidden:withAnimation:

But,those API are deprecated in iOS 9.

So,how to get lightContent statusBar in iOS 9?

Community
  • 1
  • 1
Leo
  • 24,596
  • 11
  • 71
  • 92

3 Answers3

8

I figure it out,just post my answer. Accept any better answer

  1. Set View controller-based status bar appearance to YES,or just delete this key in info.plist
  2. Make a subclass of UIImagePickerController

    @interface BaseImagePickerController : UIImagePickerController
    
    @end
    
    
    @implementation BaseImagePickerController
    -(UIStatusBarStyle)preferredStatusBarStyle{
        return UIStatusBarStyleLightContent; 
    }
    @end
    
  3. Use this subclass

    self.imagePikerViewController = [[BaseImagePickerController alloc] init];
    
Leo
  • 24,596
  • 11
  • 71
  • 92
  • Can't believe this is the way Apple would intend for you to do it, but it's the only way I found that works. – lewis Nov 23 '16 at 07:11
1

Here is how to do that in Swift:

class BaseImagePickerController {
    func preferredStatusBarStyle() -> UIStatusBarStyle {
        return UIStatusBarStyleLightContent
    }
}

To initialize it:

self.imagePikerViewController = BaseImagePickerController()

It seems that statusBarStyle was deprecated, but UIStatusBarStyle was not.

enter image description here

You can also change the color for just one view controller this way:

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

Or in the didFinishLaunchingWithOptions in the AppDelegate file you can change it in the whole app with this:

UIApplication.sharedApplication().statusBarStyle = .LightContent
Caleb Kleveter
  • 11,170
  • 8
  • 62
  • 92
1

Instead of subclassing UIImagePickerController you could use an extension on UINavigationController which UIImagePickerController is a subclass of and override preferredStatusBarStyle(). This gets rid of all issues in this context.

extension UINavigationController{

override public func preferredStatusBarStyle() -> UIStatusBarStyle {

    return .LightContent
}

}

Matthias
  • 11
  • 2