Change Status Bar Background Color in Swift 3

前端 未结 14 1593
挽巷
挽巷 2020-11-28 04:21

In XCode 7.3.x ill changed the background Color for my StatusBar with:

func setStatusBarBackgroundColor(color: UIColor) {
guard  let statusBar = UIApplicatio         


        
14条回答
  •  -上瘾入骨i
    2020-11-28 04:56

    For Xcode 9 and iOS 11: The style of the status bar we will try to achieve is a status bar with white content. Go to the ViewController.swift file and add the following lines of code.

    override var preferredStatusBarStyle: UIStatusBarStyle {
    
         return .lightContent
    
    }
    

    Or from project settings option you can change status bar's style:

    Next, go back to the Storyboard, Select the View Controller and in the Editor menu Select Embed in Navigation Controller. Select the Navigation Bar and in the Attribute Inspector set the Bar Tint color to red. The Storyboard will look like this.

    Build and Run the project, The content of the status bar is dark again, which is the default. The reason for this is, iOS asked for the style of the status bar of the navigation controller instead of the contained view controller.

    To change the style of all navigation controller inside the app, change the following method in the AppDelegate.swift file.

      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
    
        UINavigationBar.appearance().barStyle = .blackOpaque
        return true
        }
    

    Build and Run the Project again, this time the content of the status bar changed to white.

提交回复
热议问题