更改 UIToolbar 的颜色 +它是在 iPad 上的 Popover 控制器中呈现时的按钮
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎是一个名为 barStyle 的属性,而不是我之前所想的tintColor。最简单的解决方案是从其他地方复制栏样式:
然后确保样式在视图更改时保持正确是相当简单的。虽然我不得不说我非常喜欢旋转后银色导航栏上的深蓝色黑色按钮。
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:
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.