更改 UIToolbar 的颜色 +它是在 iPad 上的 Popover 控制器中呈现时的按钮

发布于 2024-10-05 05:29:07 字数 1307 浏览 6 评论 0原文

在 iPhone 和 iPad 上,我都需要在导航栏的右侧显示两个按钮。我使用以下代码片段执行此操作:

UIToolbar *rightBarButtons = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 92, 44.01)];
UIBarButtonItem *send = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction 
                                                                      target:self 
                                                                      action:@selector(send)];
[send setStyle:UIBarButtonItemStyleBordered];
UIBarButtonItem *add =  [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 
                                                                      target:self
                                                                      action:@selector(addRecipe:)];
[add setStyle:UIBarButtonItemStyleBordered];
NSArray *buttons = [[NSArray alloc] initWithObjects:send,add,nil];
[send release];
[add release];
[rightBarButtons setItems:buttons];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBarButtons];
[buttons release];
[rightBarButtons release];

在 iPhone 上,颜色很好,在 iPad 上的横向模式下,颜色很好,因为它们是灰色的。然而,在纵向模式下,视图出现在具有深黑色/蓝色的弹出控制器内。我的按钮和工具栏显示为默认灰色。

如何使工具栏按钮匹配?如果您不使用上面的技巧,而只像平常一样显示一个按钮,则会处理颜色更改,我想我只需要手动实现颜色更改,问题是,我似乎根本无法更改颜色。

On both the iPhone and the iPad I have a need to present two buttons on the right hand side of a navigation bar. I'm doing this with the following snippet of code:

UIToolbar *rightBarButtons = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 92, 44.01)];
UIBarButtonItem *send = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction 
                                                                      target:self 
                                                                      action:@selector(send)];
[send setStyle:UIBarButtonItemStyleBordered];
UIBarButtonItem *add =  [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 
                                                                      target:self
                                                                      action:@selector(addRecipe:)];
[add setStyle:UIBarButtonItemStyleBordered];
NSArray *buttons = [[NSArray alloc] initWithObjects:send,add,nil];
[send release];
[add release];
[rightBarButtons setItems:buttons];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBarButtons];
[buttons release];
[rightBarButtons release];

On the iPhone the colours are fine, and in landscape mode on the iPad it is fine as they are grey. However in portrait mode the view appears inside a popover controller which has a dark black/blue colour. My buttons and the toolbar show up as the default grey.

How can I make the toolbar buttons match? If you do not use the hack above and just present one button as normal the colour change is handled and I guess I just need to implement that colour change manually, problem is, I can't seem to get the colour to change at all.

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

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

发布评论

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

评论(1

轻许诺言 2024-10-12 05:29:07

这似乎是一个名为 barStyle 的属性,而不是我之前所想的tintColor。最简单的解决方案是从其他地方复制栏样式:

[rightBarButtons setBarStyle:self.navigationController.navigationBar.barStyle];

然后确保样式在视图更改时保持正确是相当简单的。虽然我不得不说我非常喜欢旋转后银色导航栏上的深蓝色黑色按钮。

This would appear to be a property called barStyle and not tintColor as I previously thought. The simplest solution is to copy the bar style from elsewhere:

[rightBarButtons setBarStyle:self.navigationController.navigationBar.barStyle];

It's then fairly trivial to ensure the style remains correct as the view changes. Although I have to say I quite liked the dark blue black buttons over the silver navigation bar that gave after rotation.

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