Change UINavigationItem colour

前端 未结 3 1404
清酒与你
清酒与你 2021-01-05 23:27

I need to set custom colors to my UINavigationBar buttons. I\'m doing the following thing(RGB func is a define):

- (void)viewWillAppear:(BOOL)animated
{

for         


        
相关标签:
3条回答
  • 2021-01-05 23:31

    Here's one way:

    [[theNavigationBar.subviews objectAtIndex:1] setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [[theNavigationBar.subviews objectAtIndex:2] setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    

    However, HUGE, caveat. This is highly likely to break on a future OS release and is not recommended.

    At the very least you should perform a lot of testing and make sure you your assumptions of the subview layout of the navigation bar are correct. or You can change the color by changing the tintColor property of the UINavigationBar

    myBar.tintColor = [UIColor greenColor];
    

    or You can follow the below link http://www.skylarcantu.com/blog/2009/11/05/changing-colors-of-uinavigationbarbuttons/

    0 讨论(0)
  • 2021-01-05 23:57

    [Change UINavigationItem colour](http://www.skylarcantu.com/blog/2009/11/05/changing-colors-of-uinavigationbarbuttons/"Changing colors of UINavigationBarButtons") and to set same color to UISegmentControl will help you to reach to your destination.

    Here is a sample code for to set color to UISegmentControl.

    0 讨论(0)
  • 2021-01-05 23:57

    For IOS5 will have to use "setBackgroundImage:forBarMetrics:"

    try this code to apply all UINavigationItem / UINavigationBar

     if([[UINavigationBar class] respondsToSelector:@selector(appearance)]){ //iOS >=5.0
        //use for UINavigationBar Custom image.
        [[UINavigationBar appearance] setBackgroundImage:[UIImage imageWithNamed:@"navImage.png"] forBarMetrics:UIBarMetricsDefault];
    
        //use for UINavigationItem custom color
        [[UINavigationBar appearance] setTintColor:[UIColor greenColor]];
    }
    
    0 讨论(0)
提交回复
热议问题