简体   繁体   中英

How can I make a navigation bar's color any color I want?

I created a navigation bar programmatically, and as far as I know, you can only make it "UIColor BlackColor" or "WhiteColor" or whatever. So the options are limited. Is there a way to be able to choose from a color palette or something, or use RGB sliders or some way to have thousands of color options?

Sure. You can make an arbitrary UIColor like so:

UIColor *theColor = [UIColor colorWithRed:0.5f
                                    green:0.75f
                                     blue:0.0f
                                    alpha:1.0f];

You can set the color by using the command:

    navigationController.navigationBar.tintColor = [UIColor colorWithRed: green: blue: ] 

Or the pre made colors in UIColor by typing:

    [UIColor blueColor]; 

"blue" being able to be replaced with many basic colors like black, red, grey, green, etc.

But if you want an image as the background of the NavBar, you need to make a custom class that is a subclass of UINavigationBar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM