I want to develop UINavigationBar
and also set background color for that. I have created the UINavigationBar
but I have problem with setting backgroundcolor. anyone please help me. Thanks.
问题:
回答1:
[self.navigationController.navigationBar setBackgroundColor:[UIColor redColor]];
Try like this. I think it will be helpful to you.
Edit: updated the code to actually compile.
回答2:
In the new iOs this it how it works:
self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
self.navigationController.navigationBar.barTintColor =[UIColor colorAzulNavegacion];
回答3:
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()
回答4:
You could use the tint property of the UINavigationBar
to change it's color. Check this article about it. There is also UIAppearance
, that allows you to change the background of every UINavigationBar
of your application, which is quite powerfull in my opinion. You can check this.
回答5:
You can set the tint color by using navbar.tintColor = [UIColor redColor];
See the reference here: apple docs
回答6:
Try this:
navigationBar.tintColor = [UIColor blackColor];
回答7:
self.navigationController?.navigationBar.translucent = false
self.navigationController?.navigationBar.barTintColor = UIColor.redColor()
self.navigationController?.navigationBar.barStyle = UIBarStyle.BlackTranslucent
回答8:
You can customize a UINavigationBar
with the following propertys:
@property(nonatomic, assign) UIBarStyle barStyle
@property(nonatomic, retain) UIColor *tintColor
setBackgroundImage:forBarMetrics:
@property(nonatomic, copy) UIColor *backgroundColor
For more methods and propertys please check the class reference of UINavigationBar
and UIView
回答9:
self.navigationController.navigationBar.tintColor = [UIColor blackColor];