The navbar color appears faded at the top. I'm using a UINavigationController, and the navbar is showing up a lot lighter than it should. Any ideas on how to fix it? Here is my code:
self.navigationController!.navigationBar.hidden = false
self.navigationController!.navigationBar.backgroundColor = UIColor(red: 0.459, green: 0.102, blue: 1, alpha: 1)
let titleDict: NSDictionary = [NSForegroundColorAttributeName: UIColor.whiteColor()]
self.navigationController!.navigationBar.titleTextAttributes = titleDict as? Dictionary
self.navigationController!.navigationBar.tintColor = UIColor.whiteColor()
Add these lines to your .plist file. Then, set style Black and you problem should be fixed.
1.Do the following change
2.You are setting background color so it is faded but we have to set bartint color
self.navigationController?.navigationBar.barTintColor = UIColor.red
This will set the bartint color to red, you can set any you want
Related
I am building a Swift app and I am trying to change the color of the navigation bar.
I'm trying to do it directly from Xcode without code on the main.storyboard.
I've tried changing several settings in the Xcode Attribute Inspector but nothing has worked. I've also searched StackOverFlow but all the answers I find are are changing it programatically.
Does anyone know how to change the color of it directly from the Attribute Inspector?
Thanks.
You just need to click on the navbar and in attribute inspector, there is an option for Background, you can provide any color which you want to give. In my case, I selected a custom sky blue color.
You can use
navigationBar.barTintColor = UIColor.whiteColor()
or you do this by Storyboard Like this.
💡 Navigation Bar:
navigationController?.navigationBar.barTintColor = UIColor.green
Replace greenColor with whatever UIColor you want
💡 Navigation Bar Text:
navigationController?.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.orange]
Replace orangeColor with whatever color you like.
💡 Tab Bar:
tabBarController?.tabBar.barTintColor = UIColor.brown
💡 Tab Bar Text:
tabBarController?.tabBar.tintColor = UIColor.yellow
On the last two, replace brownColor and yellowColor with the color of your choice.
💡swift navigation bar title color:
Place this in your didFinishLaunchingWithOptions method in the AppDelegate.
let attrs = [
NSAttributedString.Key.foregroundColor: UIColor.white
]
UINavigationBar.appearance().titleTextAttributes = attrs
In the storyboard, change the background color. It will work.
Try it:
if #available(iOS 13.0, *) {
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = UIColor(red: 21/255, green: 46/255, blue: 82/255, alpha: 1)
appearance.titleTextAttributes = [.foregroundColor: UIColor.white, .font: UIFont(name: "Arial", size: 32)!]
navigationController?.navigationBar.standardAppearance = appearance
navigationController?.navigationBar.scrollEdgeAppearance = navigationController?.navigationBar.standardAppearance
navigationController?.navigationBar.compactAppearance = appearance.copy()
}
so I'm using the native "more" function for tab bars in Xcode. I've managed to style the navigation bar & title color programmatically.
//sets the font color
UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor.rawValue: UIColor.white]
//sets the tint color, which dictates the button color
UINavigationBar.appearance().tintColor = UIColor.white
//sets the Bar tint color
UINavigationBar.appearance().barTintColor = UIColor(red: 0/255, green: 175/255, blue: 65/255, alpha: 1.0)
But is there a way to change the tint on these blue icons (reference images below)? The images I'm uploading are green, but it's being tinted & I can't find the setting. Does anyone know how to change this?
Image 1, Image 2
You only need to initialize the image:
UIImage.(withRenderingMode: .alwaysTemplate)
and then change
UIImageView.tintColor = .green
I have a UIView called SearchView, and I am adding the searchController.searchBar as a subview of the UIView.
Inside viewDidLoad(), I am changing the search bar in my UISearchController like so:
//makes background transparent
searchController.searchBar.backgroundImage = UIImage()
//makes magnifying glass white
let iconView:UIImageView = tf!.leftView as! UIImageView
iconView.image = iconView.image?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
iconView.tintColor = UIColor.whiteColor()
//changes text color to white
let tf = searchController.searchBar.valueForKey("searchField") as? UITextField
let attributedString = NSAttributedString(string: "", attributes:[NSForegroundColorAttributeName : UIColor.whiteColor()])
tf!.attributedPlaceholder = attributedString
tf!.textColor = UIColor.whiteColor()
//changes search field background color
tf!.backgroundColor = UIColor(red: 82/255, green: 91/255, blue: 93/255, alpha: 1)
//HERE: should make the cancel button font white...
searchController.searchBar.tintColor = UIColor.whiteColor()
searchView.addSubview(searchController.searchBar)
And in the AppDelegate, I have
UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).tintColor = UIColor.whiteColor()
In your app delegate at launch time, say this:
UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).tintColor = UIColor.whiteColor()
Note that this will have an effect only when there is editing going on in the search bar. If there is no editing in the search bar, there is nothing to cancel, so the Cancel button is dimmed and has no color (it's a kind of grey based on the tint color).
When I switch to another screen, the navigation bar (white) turns gray (if I put another color took a darker shade of the same color)
This is my code to choose the color
self.navigationController!.navigationBar.barTintColor = UIColor.whiteColor()
self.navigationController!.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.blackColor()]
self.navigationController!.navigationBar.translucent = false
Any idea to prevent this from happening and keep the color I want
Try below, it will surely works.
self.navigationController!.navigationBar.translucent = false;
self.navigationController!.navigationBar.barTintColor = UIColor.whiteColor()
self.navigationController!.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.blackColor()]
while going to other screen your navigation bar turns gray because, On iOS7 and later, translucent property of UINavigationBar is true by default.
Try this :
1)
var controller= UINavigationController(rootViewController:YourViewController)
controller.navigationBar.tintColor = [UIColor whiteColor];
2)
var navigationBarAppearace = UINavigationBar.appearance()
navigationBarAppearace.tintColor = UIColor.whiteColor()
navigationBarAppearace.barTintColor = UIColor.whiteColor()
I try to set my navigation bar transparent regarding a image below this, something like the following image :
I tried the solution in transparent navigation bar ios but I don't get the above result, I get only the icon on the left but without any color in the navigation bar, completely transparent. But if I set a background color the transparency disappears at all.
There is any way to set a color in the navigation bar and make it transparent??
Thanks in advance.
just checked on the 8.1 simulator and got very similar result to your picture
let bar:UINavigationBar! = self.navigationController?.navigationBar
bar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
bar.shadowImage = UIImage()
bar.backgroundColor = UIColor(red: 0.0, green: 0.3, blue: 0.5, alpha: 0.3)
main point here is background color with alpha.
Check attached image, maybe I missed something?
To set this style globally, use the UIAppearance APIs. In AppDelegate's application:didFinishLaunchingWithOptions: add the following code:
// Sets background to a blank/empty image
UINavigationBar.appearance().setBackgroundImage(UIImage(), forBarMetrics: .Default)
// Sets shadow (line below the bar) to a blank image
UINavigationBar.appearance().shadowImage = UIImage()
// Sets the translucent background color
UINavigationBar.appearance().backgroundColor = UIColor(red: 0.0, green: 0.3, blue: 0.5, alpha: 0.3)
// Set translucent. (Default value is already true, so this can be removed if desired.)
UINavigationBar.appearance().translucent = true
Have you tried setting the navigationBar's alpha property? In your root view controller to the navigation controller...
[self.navigationController.navigationBar setBackgroundColor:[UIColor greenColor]];
[self.navigationController.navigationBar setAlpha:0.3f];
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.backgroundColor = UIColor.clear
self.navigationController?.navigationBar.isTranslucent = true
If the above code is not working then set edgesForExtendedLayout to all.
self.edgesForExtendedLayout = .all