How can I change the text color of UITabBar (which is contained in UINavigationController if it's matters) ?
If I write this -
UITabBar.appearance().tintColor = UIColor.greenColor()
then the color would be green as expected, but if I write this -
UITabBar.appearance().tintColor = UIColor(red: 255, green: 255, blue: 255, alpha: 1.0)
The text becomes invisible
The same goes for
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.redColor()], forState:.Selected) //red color
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor(red: CGFloat(104), green: CGFloat(154), blue: CGFloat(26), alpha: CGFloat(1))], forState:.Selected) //invisible
Please try writing it like this:
UITabBar.appearance().tintColor = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)
You must divide the red, green and blue by 255, like this
UIColor(red:255/255.0, green:255/255.0, blue: 255/255.0, alpha: 1.0)
Related
I have this weird behavior on my navigationBar:
And I don't know how to fix it.
My settings on storyboard are:
I want the bar tint to be .clear so I can have the perfect blur effect.
Any ideas?
Thanks for your attention.
try these settings it may help
self.navigationController?.navigationBar.isOpaque = true
UIApplication.shared.statusBarView?.backgroundColor = UIColor.init(red: 180/255, green: 40/255, blue: 56/255, alpha: 1.0)
self.navigationController?.navigationBar.barTintColor = UIColor.init(red: 180/255, green: 40/255, blue: 56/255, alpha: 1.0)
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.view.backgroundColor = UIColor.init(red: 180/255, green: 40/255, blue: 56/255, alpha: 1.0)
tried this
UINavigationBar.appearance().barTintColor = UIColor(red: 1/255, green: 68/255, blue: 148/255, alpha: 1)
UINavigationBar.appearance().tintColor = UIColor.white
UINavigationBar.appearance().titleTextAttributes =[NSForegroundColorAttributeName:UIColor.white]
and also tried this
UINavigationBar.appearance().barTintColor = UIColor(red: 1, green: 68, blue: 148, alpha: 1)
UINavigationBar.appearance().tintColor = UIColor(red: 1, green: 68, blue: 148, alpha: 1)
UINavigationBar.appearance().backgroundColor = UIColor(red: 1, green: 68, blue: 148, alpha: 1)
Can anyone help me achieve correct color. I must be using the various params wrong
thanks
UINavigationBar.appearance().barTintColor = UIColor(red: 1.0/255.0, green: 68.0/255.0, blue: 148.0/255.0, alpha: 1.0)
Give Float values
Your code will always return 0 .
Change
UINavigationBar.appearance().barTintColor = UIColor(red: 1/255, green: 68/255, blue: 148/255, alpha: 1)
to
UINavigationBar.appearance().barTintColor = UIColor(red: 1.0/255.0f, green: 68.0/255.0f, blue: 148.0/255.0f, alpha: 1.0)
I have view which has background color like this:
self.view.backgroundColor = UIColor(red: 15/255, green: 52/255, blue: 100/255, alpha: 1)
And i have navBar which has color like:
nav1.navigationBar.tintColor = UIColor(red: 15/255, green: 52/255, blue: 100/255, alpha: 1)
They has different colors, how to solve this problem?
please use this to change the navigation bar background color
if floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1
{
// iOS 6.1 or earlier
self.navigationController!.navigationBar.tintColor = UIColor(red: 15/255, green: 52/255, blue: 100/255, alpha: 1)
}
else
{
// iOS 7.0 or later
self.navigationController!.navigationBar.barTintColor = UIColor(red: 15/255, green: 52/255, blue: 100/255, alpha: 1)
self.navigationController!.navigationBar.translucent = false
}
go to the story board than go to attribute inspector
the is a column extension edges uncheck the option under the top bar. your color wold look different.
Try nav1.navigationBar.alpha = 1
I cannot to set my RGB color to UINavigationBarand ToolBar. I tried it
let myColor = UIColor(red: 47, green: 206, blue: 255, alpha: 1.0)
self.navigationController?.navigationBar.barTintColor = myColor
self.navigationController?.toolbar.tintColor = myColor
Also I tried HSB color
let secondColor = UIColor(hue: 194, saturation: 82, brightness: 100, alpha: 1.0)
self.navigationController?.navigationBar.barTintColor = secondColor
self.navigationController?.toolbar.tintColor = secondColor
But when I wrote the following method it works.
self.navigationController?.navigationBar.barTintColor = UIColor.greenColor()
self.navigationController?.toolbar.tintColor = UIColor.greenColor()
How can I set my RGB color to bars?
let myColor = UIColor(red: 47, green: 206, blue: 255, alpha: 1.0)
is incorrect. UIColor requires color components in a range 0.0 ... 1.0. So you probably need
let myColor = UIColor(red: 47.0/255.0, green: 206.0/255.0, blue: 255.0/255.0, alpha: 1.0)
From the UIColor docs
UINavigationBar.appearance().barTintColor = UIColor(red: 73.0 / 255.0, green: 155.0 / 255.0, blue: 255.0/ 255.0, alpha: 1.0)
// set the navigation style
self.navigationController?.navigationBar.barTintColor = UIColor(red: 29.0/255.0, green: 202.0/255.0, blue: 255.0/255.0, alpha: 1)
self.navigationController?.navigationBar.barStyle = UIBarStyle.Black
// set the cancel button color to white
cancel.tintColor = UIColor.whiteColor()
// tweet and chars left (140) to white
tweet.tintColor = UIColor.whiteColor()
charsLeftLabel.textColor = UIColor.whiteColor()
// set the color of the view containing the above two buttons to the same color as the navigation
view.backgroundColor = UIColor(red: 29.0/255.0, green: 202.0/255.0, blue: 255.0/255.0, alpha: 1)
the view in the navigation and the navigation itself have two different shades although I'm using the same UI Color shades
Why is this happening?
Just try using the following code
[self.view setBackgroundColor:[UIColor clearColor]];
instead of
view.backgroundColor = UIColor(red: 29.0/255.0, green: 202.0/255.0, blue: 255.0/255.0, alpha: 1)
Even the RGB values in the view background is 40, 197, 251 and your navigation bar is having 69, 209, 255
Try this code to set navigation bar and view background colour. :
self.navigationController?.navigationBar.barStyle = UIBarStyle.Black
self.navigationController?.navigationBar.tintColor = UIColor.whiteColor()
self.navigationController?.navigationBar.barTintColor = UIColor(red: 29.0/255.0, green: 202.0/255.0, blue: 255.0/255.0, alpha: 1)
self.navigationController?.navigationBar.translucent = false
self.view.backgroundColor = UIColor(red: 29.0/255.0, green: 202.0/255.0, blue: 255.0/255.0, alpha: 1)