I want to develop UINavigationBar
and also set background color for that. I have created the UINavigationBar
but I have problem with setting backgr
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()
[self.navigationController.navigationBar setBackgroundColor:[UIColor redColor]];
Try like this. I think it will be helpful to you.
Edit: updated the code to actually compile.
self.navigationController?.navigationBar.translucent = false
self.navigationController?.navigationBar.barTintColor = UIColor.redColor()
self.navigationController?.navigationBar.barStyle = UIBarStyle.BlackTranslucent