设置 iPhone 应用程序导航栏中 2 个按钮的色调颜色

发布于 2024-09-25 06:54:57 字数 512 浏览 2 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无风消散 2024-10-02 06:54:57

这是合法的做法。

如果(富)
b.tintColor = [UIColor colorWithRed:0.83 绿色:0.43 蓝色:0.57 alpha:0.5];

希望这有帮助。我已经帮助了您,您可以通过单击此作为正确答案来帮助我们,这样我们就知道这实际上对您有用,并且这将成为其他人的参考点,因为您可以帮助确认这对您有用。

如果您需要更多帮助,请告诉我

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文