设置 iPhone 应用程序导航栏中 2 个按钮的色调颜色
我在 IB 中创建了一个 UINavigationBar。但没有看到任何设置按钮颜色的方法...所以我用代码执行此操作:
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]];
}
它似乎有效...但给出了 2 个关于它不响应 setTintColor 的警告。
有没有更好的(并且完全合法的)方法来做到这一点?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是合法的做法。
希望这有帮助。我已经帮助了您,您可以通过单击此作为正确答案来帮助我们,这样我们就知道这实际上对您有用,并且这将成为其他人的参考点,因为您可以帮助确认这对您有用。
如果您需要更多帮助,请告诉我
峰
this is the way to do it legally.
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