Remove Translucency of UIStatusBar - ios

I am trying to make my UIStatusBar not translucent at all.
While my UINavigationBar is completely white, I want the UIStatusBar to follow that behavior.
In my appDelegate - didFinishLaunchingWithOptions I was trying:
UIApplication.sharedApplication().statusBarStyle = .Default
But there is no way for me to set e.g. the alpha or translucency.
Any ideas?

1) In your info.plist file insert a new record with key "View controller-based status bar appearance" and set it to NO
2) In case the previous step does not work:
In your application(_:didFinishLaunchingWithOptions:) method of the AppDelegate.swift file put
UIApplication.sharedApplication().statusBarStyle = .LightContent // or .default
3) Try this inside your controller:
override var preferredStatusBarStyle: UIStatusBarStyle {
return .default
}
4) Put this in your viewDidLoad method:
self.setNeedsStatusBarAppearanceUpdate()

Related

Color of status bar on Xcode 9.3 not changing despite overriding

I've used the following code:
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
It does work on my initial view controller scene, but it does not work on any other ones.
I've put the same function on each viewcontroller's Swift file.
Thanks in advance.
You can change the info.plist the row View controller-based status bar appearance and set it to NO
Then put this line of code in your appDelegate.swift in didFinishLaunchingWithOptions
UIApplication.shared.statusBarStyle = .lightContent
When you override preferredStatusBarStyle in a viewcontroller then it will work for that controller. But if you want to change whole application status bar style then put this line of code in you AppDelegate class.
UIApplication.shared.statusBarStyle = .lightContent
Perform the below changes to keep the status bar of color white.
Set View controller-based status bar appearance in info.plist = No
In AppDelegate, set UIApplication.shared.statusBarStyle = .lightContent
1.Change in info.plist the row View controller-based status bar appearance and set it to NO
2.Change in appDelegate.swift in didFinishLaunchingWithOptions
UIApplication.shared.statusBarStyle = .lightContent

Put status Bar Color in LightContent

I try to put my Status Bar in Light Content.
The problem is that I have set View controller-based status bar
appearance to YES .
In my ViewController I put :
override open var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
I also try to put this in my AppDelegate :
application.statusBarStyle = .lightContent
After thats I still have a Dark (black) Status Bar.
ios 10 and swift 3
Change in info.plist the row View controller-based status bar appearance and set it to NO
Change in appDelegate.swift in didFinishLaunchingWithOptions
UIApplication.shared.statusBarStyle = .lightContent
In perticular viewcontroller use
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
In your ViewController's viewDidLoad method try calling
self.setNeedsStatusBarAppearanceUpdate()
didFinishLaunching Method in AppDelegate Class Single line code.
application.statusBarStyle = .lightContent
Here is Apple Guidelines/Instruction about status bar change. Only Dark & light (while & black) are allowed 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 to YES 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.

Set color of text in status bar it is not working (swift 3 - iOS 10)

My status bar is black and I'm trying to set as white, so I did what I found in some questions here and put this on my AppDelegate...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//Status bar color
UIApplication.shared.statusBarStyle = .lightContent
return true
}
There is no error in my console, nothing about this. The status bar text is still black. What could be causing this? There is another way to do that in swift 3.0?
ensure once in your project info.plist the row
View controller-based status bar appearance and set it to NO
In Swift3 you have to use following code, put anywhere in your view controller
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
Here is Apple Guidelines/Instruction about status bar change. Only Dark & light (while & black) are allowed 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 to YES 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
}

How can I change my status bar text color. Screenshot attached

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?
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 to YES 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:
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;
}
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
Text color of status bar could be white or black.

Status Bar Style - Swift 3 - change at any time

I'm finding it hard to change the status bar style programatically.
I see how to statically set it for each ViewController using a combo of (in ViewController.swift):
override var preferredStatusBarStyle: UIStatusBarStyle {
return UIStatusBarStyle.default
}
and (in info.plist):
View controller-based status bar appearance = YES
...
I'm looking to change it whenever I want!
Found the answer after quite a lot of digging!
Set (in info.plist):
View controller-based status bar appearance = NO
and remove the (in ViewController.swift):
override var preferredStatusBarStyle: UIStatusBarStyle {
return UIStatusBarStyle.default
}
...
Now you can use (in ViewController.swift):
UIApplication.shared.setStatusBarStyle(UIStatusBarStyle.lightContent, animated: true)
And, to initially set the style for each ViewController, use viewDidAppear:
override func viewDidAppear(_ animated: Bool) {
UIApplication.shared.setStatusBarStyle(UIStatusBarStyle.lightContent, animated: false)
}
swift 3
1.Change in info.plist the row View controller-based status bar appearance and set it to NO
2.Change in appDelegate.swift in didFinishLaunchingWithOptions
UIApplication.shared.statusBarStyle = .lightContent
Store the status bar style as a property in your view controller:
var statusBarStyle: UIStatusBarStyle = .default
And then implement preferredStatusBarStyle in the same view controller:
override var preferredStatusBarStyle: UIStatusBarStyle {
return statusBarStyle
}
Then when you change statusBarStyle make sure to also call setNeedsStatusBarAppearanceUpdate. The preferredStatusBarStyle method is automatically called when the view appears/disappears, but if you change the status bar style while your view is visible, you have to tell the view controller the status bar appearance needs updating.
Note you still need to make the changes to the plist, and if your view controller is in a navigation controller, you may need to handle the status bar changes there instead (via a UINavigationController subclass, for example).
UIApplication.shared.setStatusBarStyle(…) was deprecated in iOS 9.0, so don't use that.

Resources