【问题标题】:How can I get a 'matte' color on a UINavigationBar?如何在 UINavigationBar 上获得“哑光”颜色?
【发布时间】:2011-08-23 18:08:24
【问题描述】:

如何在 UINavigationBar 上获得哑光颜色而不是闪亮的外观?

[self.navigationController.navigationBar setTintColor:[UIColor blackColor]];

【问题讨论】:

    标签: iphone objective-c cocoa-touch uinavigationbar uicolor


    【解决方案1】:

    没有内置的方法可以做到这一点。使用tintColor 将始终让您获得默认的“闪亮”外观。另一种方法是自己绘制条形图,使用here 描述的技术,以获得您想要的外观。

    【讨论】:

    • FWIW,似乎投票和接受最多的答案不是一个好主意,因为它显然(见那里的 cmets)在 iOS5 中不起作用。 UINavigationBar 必须是子类,而不是使用覆盖 drawRect: 的类别进行扩展
    • 为什么要子类化?在 iOS 5 中有一个方法 setBackgroundImage:forBarMetrics: 那么在您的类别中为什么不先检查 respondsToSelector: 然后使用适当的方法?
    【解决方案2】:

    我使用类别 UINavigationBar 的简单方法:

    @implementation UINavigationBar (UINavigationBarWithoutShiny)
    - (void)drawRect:(CGRect)rect {}
    @end
    

    在此之后我可以只使用 UINavigationBar 视图的背景颜色:

    self.navigationController.navigationBar.backgroundColor = [UIColor greenColor];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-19
      • 2015-08-31
      • 2013-02-24
      • 1970-01-01
      • 1970-01-01
      • 2015-06-12
      相关资源
      最近更新 更多