开发者

Setting the tintColor for 2 buttons in an iPhone app Nav-Bar

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?


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜