Set background color for UINavigationBar

前端 未结 9 591
滥情空心
滥情空心 2020-12-18 07:07

I want to develop UINavigationBar and also set background color for that. I have created the UINavigationBar but I have problem with setting backgr

相关标签:
9条回答
  • 2020-12-18 07:52

    I have to look this up every time so adding my answer here (Swift). The code below is setting this for all navigation bars in the app. You could set each of these on individual navigation bars too if you wanted to.

    You can set the translucency, title text color, background color (this is called barTintColor, thanks, Apple!), and bar button item foreground color, like so:

        // 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()
    
    0 讨论(0)
  • 2020-12-18 07:56
    [self.navigationController.navigationBar setBackgroundColor:[UIColor redColor]];
    

    Try like this. I think it will be helpful to you.

    Edit: updated the code to actually compile.

    0 讨论(0)
  • 2020-12-18 07:57

    self.navigationController?.navigationBar.translucent = false

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

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

    0 讨论(0)
提交回复
热议问题