iOS Custom Status Bar Background Color not displaying

后端 未结 9 1856
别那么骄傲
别那么骄傲 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:57

    There is a main difference in tintColor and changing the background color of UINavigationBar. The best way in my opinion is apply a background image, made by 1 pixel square image of just one color.
    Like that:

    let tabbarAndNavBarBkg = UIImage(named: "nav_tab")
    UINavigationBar.appearance().setBackgroundImage(tabbarAndNavBarBkg, forBarMetrics: .Default) 
    

    Or you can create a category on UIColor to return a UIImage given a UIColor instance, in objC:

    + (UIImage *) imageWithColor:(UIColor*) color {
        CGRect rect = CGRectMake(0, 0, 1, 1);
        UIGraphicsBeginImageContext(rect.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSetFillColorWithColor(context, color.CGColor);
        CGContextFillRect(context, rect);
        UIImage *colorImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return colorImage;
    }
    

提交回复
热议问题