更改 UIBarButtonItem 颜色

发布于 2024-09-04 03:31:15 字数 261 浏览 3 评论 0原文

这是一个非常简单的问题,我真的找不到答案!

所以好吧,默认情况下,如果我设置 UIToolbar 的tintColor,UIBarButtonItem 的颜色将是相同的。

我只想更改 UIBarButtonItems 的颜色并更改其文本的颜色。

有人知道如何做到这一点吗?

我真的不敢相信它是如此复杂,真的...更改 UIButton 属性是如此简单,我不明白为什么它与 UIBarButtonItem 不一样...

非常感谢!

This is a pretty simple question and I really can't find the answer!

So okay, by default if I set the tintColor of a UIToolbar, the UIBarButtonItem's colors will be the same.

I only want to change the colors of my UIBarButtonItems and also change their text's colors.

Is there anybody out there having an idea on how to do so?

I really can't believe it is so complicated, really... changing an UIButton properties is so easy, I can't see why it's not the same for an UIBarButtonItem...

Thanks so much!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

青丝拂面 2024-09-11 03:31:15

不确定您是否找到了答案。我是这样做的:

UIImage *buttonImage = [[UIImage imageNamed:@"btnGreen.png"] stretchableImageWithLeftCapWidth:10 topCapHeight:0];
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
[doneButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
[doneButton setTitle:@"Done" forState:UIControlStateNormal];    
[doneButton addTarget:self action:@selector(saveDateEdit:) forControlEvents:UIControlEventTouchUpInside];
[doneButton.titleLabel setFont:[UIFont boldSystemFontOfSize:13]];
doneButton.frame = CGRectMake(0.0, 0.0, 50, 30);
btnDone = [[UIBarButtonItem alloc] initWithCustomView:doneButton];
[doneButton release];

Not sure you found the answer. Here's how I do it:

UIImage *buttonImage = [[UIImage imageNamed:@"btnGreen.png"] stretchableImageWithLeftCapWidth:10 topCapHeight:0];
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
[doneButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
[doneButton setTitle:@"Done" forState:UIControlStateNormal];    
[doneButton addTarget:self action:@selector(saveDateEdit:) forControlEvents:UIControlEventTouchUpInside];
[doneButton.titleLabel setFont:[UIFont boldSystemFontOfSize:13]];
doneButton.frame = CGRectMake(0.0, 0.0, 50, 30);
btnDone = [[UIBarButtonItem alloc] initWithCustomView:doneButton];
[doneButton release];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文