How to change Status Bar text color in iOS
Set the
UIViewControllerBasedStatusBarAppearance
toYES
in the .plist file.In the
viewDidLoad
do a[self setNeedsStatusBarAppearanceUpdate];
Add the following method:
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
Note: This does not work for controllers inside UINavigationController
, please see Tyson's comment below :)
Swift 3 - This will work controllers inside UINavigationController
. Add this code inside your controller.
// Preferred status bar style lightContent to use on dark background.
// Swift 3
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
Swift 5 and SwiftUI
For SwiftUI create a new swift file called HostingController.swift
import Foundation
import UIKit
import SwiftUI
class HostingController: UIHostingController<ContentView> {
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
}
Then change the following lines of code in the SceneDelegate.swift
window.rootViewController = UIHostingController(rootView: ContentView())
to
window.rootViewController = HostingController(rootView: ContentView())
How to change Status Bar text color in iOS
Set the
UIViewControllerBasedStatusBarAppearance
toYES
in the .plist file.In the
viewDidLoad
do a[self setNeedsStatusBarAppearanceUpdate];
Add the following method:
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
Note: This does not work for controllers inside UINavigationController
, please see Tyson's comment below :)
Swift 3 - This will work controllers inside UINavigationController
. Add this code inside your controller.
// Preferred status bar style lightContent to use on dark background.
// Swift 3
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
Swift 5 and SwiftUI
For SwiftUI create a new swift file called HostingController.swift
import Foundation
import UIKit
import SwiftUI
class HostingController: UIHostingController<ContentView> {
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
}
Then change the following lines of code in the SceneDelegate.swift
window.rootViewController = UIHostingController(rootView: ContentView())
to
window.rootViewController = HostingController(rootView: ContentView())
How to change status bar text color immediately in Swift in iOS 13
Status bar color is not global (by default) and if you set that to not ViewControllerBased
, you can't change it anymore. So you need to change set it inside any view you need like this:
var statusBarStyle = UIStatusBarStyle.default { didSet { setNeedsStatusBarAppearanceUpdate() } }
override var preferredStatusBarStyle: UIStatusBarStyle { statusBarStyle }
these two variables help you to change the status bar. Note that you can call setNeedsStatusBarAppearanceUpdate
inside an animation block to make it animatable.
to detect when UserInterfaceStyle
change (and update statusBar color accordingly), all views and viewControllers have delegate function for that. So knowing that:
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
if traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) {
updateStatusBarColor()
}
}
And this is the function:
func updateStatusBarColor() {
switch traitCollection.userInterfaceStyle {
case .unspecified: statusBarStyle = .default
case .light: statusBarStyle = .darkContent
case .dark: statusBarStyle = .lightContent
}
}
Note that:
the ParentViewController defines the statusBarColor
. So if you are using general navigationController
or tabBarController
, A custom class for them with these codes should be enough.
How can I change my status bar text color. Screenshot attached
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:
- Set the
UIViewControllerBasedStatusBarAppearance
toYES
in the.plist
file, if you need to set status bar style at UIViewController level only. In the viewDidLoad add function -
setNeedsStatusBarAppearanceUpdate
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.
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:
How to change the status bar text color on Ios
@Antoine
Basically you can set your theme Brightness, or you can manually override the appbar brightness using the following :
appBar: new AppBar(
title: new Text(widget.title),
brightness: Brightness.light, // or use Brightness.dark
),
Do note that this will only switch between white and black status text color.
.dark
will make the status bar text WHITE, while .light
will make the status bar text BLACK.
Maybe for a more custom color, like the comment said you can view SystemChrome class.
Flutter ios and statusbar text color
It seems like there's no other answer than this :
How can i change status text bar color
I'll let people appreciate the time Hugo Passos spent documenting it.
Related Topics
Uidevice Uniqueidentifier Deprecated - What to Do Now
How to Export Uiimage Array as a Movie
Applications Are Expected to Have a Root View Controller At the End of Application Launch
Is [Uiscreen Mainscreen].Bounds.Size Becoming Orientation-Dependent in Ios8
Uilabel Sizetofit Doesn't Work With Autolayout Ios6
Set Padding For Uitextfield With Uitextborderstylenone
Core Data: Quickest Way to Delete All Instances of an Entity
How to Write a File to a Folder Located At Apple'S Files App in Swift
Append Data to a Post Nsurlrequest
How to Load an Http Url With App Transport Security Enabled in iOS 9
How to Input Currency Format on a Text Field (From Right to Left) Using Swift
How to Find Topmost View Controller on Ios
How to Send Mail from an Iphone Application
Number of Days Between Two Nsdates
How to Install iOS 6 Sdk on Xcode 5