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.
[self.navigationController.navigationBar setBackgroundColor:[UIColor redColor]];
Try like this. I think it will be helpful to you.
Edit: updated the code to actually compile.
In the new iOs this it how it works:
self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
self.navigationController.navigationBar.barTintColor =[UIColor colorAzulNavegacion];
[self.navigationController.navigationBar setBackgroundColor:[UIColor redColor]];
Try like this. I think it will be helpful to you.
Edit: updated the code to actually compile.
barTintColor
when I type it –
Ambrosia 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()
You can set the tint color by using navbar.tintColor = [UIColor redColor];
See the reference here: apple docs
Try this:
navigationBar.tintColor = [UIColor blackColor];
self.navigationController?.navigationBar.translucent = false
self.navigationController?.navigationBar.barTintColor = UIColor.redColor()
self.navigationController?.navigationBar.barStyle = UIBarStyle.BlackTranslucent
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
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
Here it is in the context of doing something useful. In this case programmatically creating/configuring a Navigation Bar item and item and setting the background to black and the title to light gray.
Swift 5, iOS 15
@objc func addButtonPushed() {
print("Add button!")
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let rightButton = UIBarButtonItem(image: UIImage(systemName: "plus"), style: .plain,
target:self, action: #selector(addButtonPushed))
let standaloneItem = UINavigationItem()
standaloneItem.title = "Herding Cats"
standaloneItem.rightBarButtonItem = rightButton
navBar.items = [standaloneItem]
navBar.delegate = self
navBar.barStyle = UIBarStyle.default
navBar.isTranslucent = true
navBar.barTintColor = .black
navBar.titleTextAttributes = [.foregroundColor: UIColor.lightGray]
.
.
.
}
© 2022 - 2024 — McMap. All rights reserved.
barTintColor
when I type it – Ambrosia