开发者

How to add custom color to navigation bar in iphone?

开发者 https://www.devze.com 2023-02-22 21:37 出处:网络
How do I set the navigation bar to a custom color (e.g. dark green) ? I know how to change the navigation bar to primary colors like green and red, using code like this:

How do I set the navigation bar to a custom color (e.g. dark green) ?

I know how to change the navigation bar to primary colors like green and red, using code like this:

UINavigationBar *bar = [self.naviga开发者_开发问答tionController navigationBar]; 
[bar setTintColor:[UIColor redColor]]; 

Thanks.


Using RGB values like this:

UINavigationBar *bar = [self.navigationController navigationBar];
[bar setTintColor:[UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:1.0]];


[[UINavigationBar appearance] setTintColor:[UIColor colorWithRed:107.0/255.0 green:145.0/255.0 blue:35.0/255.0 alpha:1.0]]; 

Place this code in Appdelegate's didfinislaunching method.It will change the color of the navigation bar for the whole app.


And to change the tint of the navigation bar background :

[self.navBar setBarTintColor:[UIColor colorWithRed:0.701 green:0.926 blue:0.000 alpha:1.000]];


[bar setTintColor:[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0]]

There are many other ways of getting your color from different kinds of components as described in the documentation.


For swift, to change the tint of the navigation bar background :

navigationController?.navigationBar.barTintColor = UIColor.red


Use like this,

UINavigationBar *bar = [self.navigationController navigationBar];
bar.barTintColor = [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:1.0];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号