iOS Custom Status Bar Background Color not displaying

后端 未结 9 1860
别那么骄傲
别那么骄傲 2020-12-16 13:30

I am trying to fill the status bar background color to orange using the following

UINavigationBar.appearance().tintColor = UIColor.orangeColor()
UINavigation         


        
9条回答
  •  感动是毒
    2020-12-16 13:56

    After what u did in info.plist to the following: View controller-based status bar appearance => NO.

    Add this code in AppDelegate.swift file under didFinishLaunchingWithOptions:

    var navigationBarAppearace = UINavigationBar.appearance()
    
    navigationBarAppearace.tintColor = uicolorFromHex(0xffffff)
    navigationBarAppearace.barTintColor = uicolorFromHex(0x2E9AFE)
    
    // change navigation item title color
    navigationBarAppearace.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()]
    
    UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent
    

    and u can select any hex code for ur choice of color..!! Enjoy..!!

    Sorry, forgot to use hexcode you will be needing this also so add this code anywhere in your AppDelegate.swift:

    func uicolorFromHex(rgbValue:UInt32)->UIColor {
    
        let red = CGFloat((rgbValue & 0xFF0000) >> 16)/256.0
    
        let green = CGFloat((rgbValue & 0xFF00) >> 8)/256.0
    
        let blue = CGFloat(rgbValue & 0xFF)/256.0
    
        return UIColor(red:red, green:green, blue:blue, alpha:1.0)
    }
    

提交回复
热议问题