Rohit
Rohit

Reputation: 2326

statusBarStyle in Swift 4

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?

Upvotes: 3

Views: 6643

Answers (5)

Ajay saini
Ajay saini

Reputation: 2460

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
}

Upvotes: 1

0yeoj
0yeoj

Reputation: 4550

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

Upvotes: 1

iOS Geek
iOS Geek

Reputation: 4855

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;
    }

Upvotes: 0

Incredible_Dev
Incredible_Dev

Reputation: 976

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
}

Upvotes: 16

Sagar Chauhan
Sagar Chauhan

Reputation: 5823

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

Upvotes: 2

Related Questions