How to Set Status Bar Tint Color on iOS 6

Set Status Bar Tint Colour

Ahh!!! I have a working solution... albeit a very dirty and makeshift solution.

  1. Simply hide the navigation bar in storyboards (As shown in image in question - uncheck Shows Navigation Bar).
  2. Drag a Navigation Bar into the view.
  3. Set it's Alpha to 0 and uncheck User Interaction Enabled - DO NOT MAKE HIDDEN
  4. Make sure the Navigation Bar is on the top - as shown in following image.

    Screen Capture

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:

  1. Position the toolbar -1 on the Y axis
  2. 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:

  1. In the Project Summary select Status Bar Style Black Transculent from the drop down menu.
  2. 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

  1. Set the UIViewControllerBasedStatusBarAppearance to YES in the .plist file.

  2. In the viewDidLoad do a [self setNeedsStatusBarAppearanceUpdate];

  3. 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:

Sample Image

After that add in your info.plist View controller-based status bar appearance and set it to NO

Sample Image

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



Leave a reply



Submit