简体   繁体   English

如何使导航栏的颜色成为我想要的任何颜色?

[英]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. 我以编程方式创建了一个导航栏,据我所知,您只能将其设置为“ UIColor BlackColor”或“ WhiteColor”等。 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? 有没有一种方法可以从调色板或其他东西中进行选择,或者使用RGB滑块或某种方式具有数千种颜色选择?

Sure. 当然。 You can make an arbitrary UIColor like so: 您可以像这样制作任意的UIColor:

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中进行预制:

    [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. 但是,如果要将图像作为NavBar的背景,则需要创建一个自定义类,该类是UINavigationBar的子类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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