views:

40

answers:

1

I've created a UINavigationBar in IB. But don't see any way to set the button colors... so I do this with code:

for(id subView in navBar.subviews) 
    if( [subView isKindOfClass:[UIButton class]] ) 
    {
       UIBarButtonItem *b = (UIBarButtonItem *)subView; 
       if( [b.title isEqualToString:@"Cancel"] )   [b setTintColor:[UIColor   redColor]];
       if( [b.title isEqualToString:@"Save"  ] )   [b setTintColor:[UIColor greenColor]];
    }

It appears to work... but gives 2 warnings about it not responding to setTintColor.

Is there a better (and fully legal) way to do that?

A: 

this is the way to do it legally.

if(foo) b.tintColor = [UIColor colorWithRed:0.83 green:0.43 blue:0.57 alpha:0.5];

Hope this helps. i've helped you you can help us by clicking this as the right answer so we know that this actually worked for you and that this will be a reference point for other people as you can help confirm that this worked for you.

If you need any more help let me know Pk

Pavan