【问题标题】:Changing colours of a UIToolbar + it's buttons when presented in a Popover Controller on the ipad在 ipad 上的 Popover 控制器中显示时更改 UIToolbar 的颜色 + 它的按钮
【发布时间】:2011-05-18 12:12:40
【问题描述】:

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

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 上的横向模式下很好,因为它们是灰色的。然而,在纵向模式下,视图出现在具有深黑色/蓝色的弹出框控制器内。我的按钮和工具栏显示为默认灰色。

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

【问题讨论】:

    标签: iphone ipad uinavigationcontroller uisplitviewcontroller uipopovercontroller


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-26
      • 2019-08-19
      相关资源
      最近更新 更多