2

I want to change status bar text color to customer color like screenshot attached.

I have used this to make it light content -

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

But text color not changing. Can anyone help?

Status bar screenshot

Krunal
  • 68,602
  • 40
  • 230
  • 241
iDilip
  • 1,012
  • 11
  • 25
  • check out `http://stackoverflow.com/questions/17678881/how-to-change-status-bar-text-color-in-ios-7`. – iAviator Mar 27 '17 at 10:44
  • @iAviator Already checked this answer but its not changing status bar text color to pink. – iDilip Mar 27 '17 at 10:45
  • But the answer in the thread is the only correct answer. Since you can not change the color of the text it self. – rckoenes Mar 27 '17 at 10:53

4 Answers4

6

Here is Apple Guidelines/Instruction about status bar change. Only Dark & light (while & black) are allowed in status bar. It does not allow to set a color (pink, as shown in your image) in status bar.

Here is - How to change status bar style:

If you want to set status bar style, application level then set UIViewControllerBasedStatusBarAppearance to NO in your `.plist' file.

if you wan to set status bar style, at view controller level then follow these steps:

  1. Set the UIViewControllerBasedStatusBarAppearance to YES in the .plist file, if you need to set status bar style at UIViewController level only.
  2. In the viewDidLoad add function - setNeedsStatusBarAppearanceUpdate

  3. override preferredStatusBarStyle in your view controller.

-

override func viewDidLoad() {
    super.viewDidLoad()
    self.setNeedsStatusBarAppearanceUpdate()
}

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
}

Set value of .plist according to status bar style setup level. enter image description here


You can set background color for status bar during application launch or during viewDidLoad of your view controller.

extension UIApplication {

    var statusBarView: UIView? {
        return value(forKey: "statusBar") as? UIView
    }

}

// Set upon application launch, if you've application based status bar
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        UIApplication.shared.statusBarView?.backgroundColor = UIColor.red
        return true
    }
}


or 
// Set it from your view controller if you've view controller based statusbar
class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        UIApplication.shared.statusBarView?.backgroundColor = UIColor.red
    }

}



Here is result:

enter image description here

Krunal
  • 68,602
  • 40
  • 230
  • 241
4

Set the UIViewControllerBasedStatusBarAppearance to YES in the .plist file.

In the viewDidLoad method, do a

[self setNeedsStatusBarAppearanceUpdate];

Add the following method:

- (UIStatusBarStyle)preferredStatusBarStyle
{ 
    return UIStatusBarStyleLightContent; 
}
Pang
  • 8,605
  • 144
  • 77
  • 113
Abhishek Gupta
  • 603
  • 5
  • 15
1

If your application will support In your application's Info.plist, set "View controller-based status bar appearance" to NO.

In appDelegate.swift, Inside the didFinishLaunchingWithOptions function, add:

UIApplication.shared.statusBarStyle = .lightContent

Best answer is described here : How to set Status Bar Style in Swift 3

barbsan
  • 3,238
  • 11
  • 18
  • 27
nirojan
  • 61
  • 2
  • Setter for 'statusBarStyle' was deprecated in iOS 9.0: Use -[UIViewController preferredStatusBarStyle] – Green Y. Feb 03 '20 at 15:37
0

Text color of status bar could be white or black.

Jagdeep Singh
  • 2,248
  • 3
  • 16
  • 23