Set Status Bar Tint Colour
Ahh!!! I have a working solution... albeit a very dirty and makeshift solution.
- Simply hide the navigation bar in storyboards (As shown in image in question - uncheck
Shows Navigation Bar
). - Drag a Navigation Bar into the view.
- Set it's
Alpha
to 0 and uncheckUser Interaction Enabled
- DO NOT MAKE HIDDEN Make sure the Navigation Bar is on the top - as shown in following image.
This way your status bar will pick up the correct colour without showing a Navigation Bar.
Hopefully a more resilient/nicer way to do this will be in a recent Xcode update.
Top Tip: To make a toolbar look like a navigation bar:
- Position the toolbar -1 on the Y axis
- Create a label (with no text) with a height of 44px, width 320px and position at 0,0. This will be the bottom border for the tab bar. For best results, take a screenshot of a page of your app and use software to get the colour of the border - this is the darkest part of the tab before the shadow begins (use this colour as the background of the label).
Status bar tint color changes to black in iOS 6
Today I ran into the same issue, but none of the sugested answers would help me.
Since I defined my own color (red, blue, green, alpha), I did not want to add a UIStatusBar via IB, I need a one-line-solution.
After testing for a while the following worked for me:
- In the Project Summary select Status Bar Style Black Transculent from the drop down menu.
In
application: didFinishLaunchingWithOptions:
enter the following line of code:self.window.backgroundColor = [UIColor redColor]; //example color
Somehow this would not work for me when setting the style via code in application: didFinishLaunchingWithOptions:
Enjoy!
Is it possible to set the Status Bar tint color, even though the navigationBar is hidden?
Instead of making your navigation bar hidden, you can change its alpha to 0 as suggested here: How to set status bar tint color on iOS 6?
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())
Status bar color in iOS 6?
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleBlackOpaque];
or
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
are the options available apart from default
How to Change the status bar color using ios with swift on internet reachability?
In your Info.plist
you need to set "View controller-based status bar appearance" to a boolean value.
If you set it to YES
then you should override preferredStatusBarStyle
function in each view controller.
If you set it to NO
then you can set the style in AppDelegate
using:
UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: true)
How to change status bar color?
Set your status bar style to dark content:
After that add in your info.plist View controller-based status bar appearance and set it to NO
UPDATE
if you want dark content only in determinate controller add setNeedsStatusBarAppearanceUpdate in viewWillAppear and after that override preferredStatusBarStyle:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
setNeedsStatusBarAppearanceUpdate()
}
override var preferredStatusBarStyle: UIStatusBarStyle {
if #available(iOS 13.0, *) {
return .darkContent
} else {
return .default
}
Begin with navigation Controller:
In your Scene delegate declare your first navigation controller:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: windowScene)
window?.makeKeyAndVisible()
let controller = UINavigationController(rootViewController: FirstViewController())
controller.navigationBar.barStyle = .black
window?.rootViewController = controller
}
in SecondViewController override the status bar style
override var preferredStatusBarStyle: UIStatusBarStyle {
if #available(iOS 13.0, *) {
return .darkContent
} else {
return .default
}
}
Is it possible to change Status Bar color for all view controllers?
Set the style of the status bar in AppDelegate.swift
:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UIApplication.shared.statusBarStyle = .lightContent
return true
}
And add the following code to your Info.plist
:
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
Related Topics
Info.Plist Utility Error: "Info.Plist Couldn't Be Opened Because There Is No Such File"
Change the Alpha Value of the Navigation Bar
Get Tapped Word from Uitextview in Swift
Opens Apple Maps App from iOS App with Directions
Swift: Natively Detect If App Has Crashed
_Unused Flag Behavior/Usage (Gcc with Objective-C)
Add a Done Button Within a Pop-Up Datepickerview in Swift
Combining Text and Images in 'Uitextview'
Override Uiappearance Property for Mfmailcomposeviewcontroller
How to Import Existing Objective C Classes in Swift
How to Dynamically Format a Number to Have Commas in a Uitextfield Entry
How to Take Screenshot of Portion of Uiview
How to Set Status Bar Tint Color on iOS 6
Uirefreshcontrol Stuck After Switching Tabs in Uitabbarcontroller
Easiest Way of Getting Reverse Geocoded Current Location from iOS
Add a Scrollview to Existing View
How to Wait for a Function to End on iOS/Swift, Before Starting the Second One