3

This is the code I written in AppDelegate class (Swift 4):

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
     UIApplication.shared.statusBarStyle = .lightContent
    goToRootViewController()
    UINavigationBar.appearance().isTranslucent = true

    UINavigationBar.appearance().shadowImage = UIImage()
    UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
    GMSServices.provideAPIKey(googleMapApiKey)
    return true
}

but my status bar is not showing the light content I dont know what is ging on, Any help?

Wings
  • 2,398
  • 23
  • 46

5 Answers5

16

For Specific ViewController Class:

In your viewcontroller class use this code below viewDidLoad() :

override var preferredStatusBarStyle : UIStatusBarStyle {
    return .lightContent
}

this will show your status bar in light content

For Whole App:

Set "View controller-based status bar appearance" Key with Value "NO" in your product's Info.plist

enter image description here

Then Use Following code in AppDelegate.Swift inside "didFinishLaunchingWithOptions":

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    
    UIApplication.shared.statusBarStyle = .lightContent
    return true
}
Community
  • 1
  • 1
Incredible_Dev
  • 956
  • 7
  • 13
  • Yes, it works for only specific ViewController. If you want for whole app set "View controller-based status bar appearance" key in you info.plist and asign it NO, Then Simply use "UIApplication.shared.statusBarStyle = .lightContent" in your AppDelegate.swift. Your problem will solved. – Incredible_Dev Mar 27 '18 at 06:43
  • It is but i done it in appdelegate but not working in my code – Wings Mar 27 '18 at 06:46
  • Did you set "View controller-based status bar appearance" key in you info.plist with value "NO" – Incredible_Dev Mar 27 '18 at 06:54
  • i try and not work, this is suggestion from X code: `Setter for 'statusBarStyle' was deprecated in iOS 9.0: Use -[UIViewController preferredStatusBarStyle]` – Hoàng Vũ Anh Nov 10 '18 at 10:14
2

Select you project and navigate to Target -> General -> Deployment Info. In that Status Bar Style is Default, Change it to Light.

enter image description here

Sagar Chauhan
  • 5,715
  • 2
  • 22
  • 56
1

Have you Change in info.plist the row View controller-based status bar appearance and set it to NO ? Because this is necessary in order to change the status bar appearance

and also if you only want to change status bar on specific view controller then you can use

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
}
Ajay saini
  • 2,352
  • 1
  • 11
  • 25
1

Setter for 'statusBarStyle' was deprecated in iOS 9.0: Use -[UIViewController preferredStatusBarStyle]

Manually setting UIApplication.shared.statusBarStyle = .lightContent under AppDelegate function -didFinishLaunchingWithOptions doesn't seem to work

First set in file Info.plist

<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

Second:

Target -> General -> Deployment Info

Set Status Bar Style to Light

0yeoj
  • 4,500
  • 3
  • 23
  • 41
0

use below code in didLoad of your specific controller

UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];

    if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {

        statusBar.backgroundColor = [self colorWithHexString:@"C2BFAB"];//set whatever color you like
       // appDel.statusBarColor = NO;
    }
iOS Geek
  • 4,825
  • 1
  • 9
  • 30