【问题标题】:Set background color for UINavigationBar为 UINavigationBar 设置背景颜色
【发布时间】:2012-06-20 07:15:18
【问题描述】:

我想开发UINavigationBar 并为此设置背景颜色。我已经创建了UINavigationBar,但我在设置背景色时遇到了问题。任何人请帮助我。谢谢。

【问题讨论】:

    标签: ios navigationbar


    【解决方案1】:
    [self.navigationController.navigationBar setBackgroundColor:[UIColor redColor]];
    

    试试这样。我想这对你会有帮助。

    编辑:更新代码以实际编译。

    【讨论】:

    • 不知道为什么,但是当我输入 Xcode 时没有弹出barTintColor
    【解决方案2】:

    在新的 iO 中它是如何工作的:

    self.navigationController.navigationBar.barStyle  = UIBarStyleBlackOpaque;
    self.navigationController.navigationBar.barTintColor =[UIColor colorAzulNavegacion];
    

    【讨论】:

    • UIBarStyleBlackOpaque 在 iOS 9 中已弃用
    【解决方案3】:

    我每次都必须查看这个,所以在这里添加我的答案 (Swift)。下面的代码为应用程序中的所有导航栏设置了此项。如果你愿意,你也可以在单独的导航栏上设置这些。

    您可以设置半透明、标题文本颜色、背景颜色(这称为 barTintColor,谢谢,Apple!)和条形按钮项目前景色,如下所示:

        // Title text color Black => Text appears in white
        UINavigationBar.appearance().barStyle = UIBarStyle.Black
    
        // Translucency; false == opaque
        UINavigationBar.appearance().translucent = false
    
        // BACKGROUND color of nav bar
        UINavigationBar.appearance().barTintColor = UIColor.redColor()
    
        // Foreground color of bar button item text, e.g. "< Back", "Done", and so on.
        UINavigationBar.appearance().tintColor = UIColor.whiteColor()
    

    【讨论】:

    • 这应该被选为最佳答案
    【解决方案4】:

    您可以使用UINavigationBar 的 tint 属性来更改它的颜色。检查此article。还有UIAppearance,它可以让你改变你的应用程序的每个UINavigationBar的背景,在我看来这非常强大。您可以查看this

    【讨论】:

      【解决方案5】:

      您可以使用navbar.tintColor = [UIColor redColor];设置色调颜色

      在此处查看参考:apple docs

      【讨论】:

        【解决方案6】:

        试试这个:

        navigationBar.tintColor = [UIColor blackColor];
        

        【讨论】:

          【解决方案7】:

          self.navigationController?.navigationBar.translucent = false

          self.navigationController?.navigationBar.barTintColor = UIColor.redColor()

          self.navigationController?.navigationBar.barStyle = UIBarStyle.BlackTranslucent

          【讨论】:

          • 基本正确,但不推荐使用 BlackTranslucent。
          【解决方案8】:

          您可以使用以下属性自定义UINavigationBar

          • @property(nonatomic, assign) UIBarStyle barStyle
          • @property(nonatomic, retain) UIColor *tintColor
          • setBackgroundImage:forBarMetrics:
          • @property(nonatomic, copy) UIColor *backgroundColor

          更多方法和属性请查看UINavigationBarUIView的类参考

          【讨论】:

            【解决方案9】:
            self.navigationController.navigationBar.tintColor = [UIColor blackColor];
            

            【讨论】:

            • 投反对票,因为不正确。 tintColor 是将用于条形按钮项目前景色的颜色,例如“返回”文本、“
            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2010-11-08
            • 2020-12-06
            • 1970-01-01
            • 2011-02-11
            相关资源
            最近更新 更多