UINavigationBar is not working with customize UIColor?

Navigation bar is behaving well with the following code:

self.navigationController?.navigationBar.layer.backgroundColor = UIColor.brownColor().CGColor

But when I am trying to implement the same thing with a RGB color, it's not working:

self.navigationController?.navigationBar.layer.backgroundColor = UIColor(red: 81, green: 139, blue: 91, alpha: 1).CGColor

seems to me strange, isn't it? Any reason why?

Upvotes: 0

Views: 44

Answers (3)

More appropriate is:

navigationController?.navigationBar.barTintColor = UIColor(red: 81/255, green: 139/255, blue: 91/255, alpha: 1)

actually what I am in need. :)

Upvotes: 0

RStack
RStack

Reputation: 230

I think you should add .0 also to get the exact colour Try this solution....

    self.navigationController?.navigationBar.layer.backgroundColor = UIColor(red: 81.0/255, green: 139.0/255, blue: 91.0/255, alpha: 1).CGColor

Upvotes: 0

Muzahid
Muzahid

Reputation: 5186

Now it will work. Because RGB value range 0 to 1.

 self.navigationController?.navigationBar.layer.backgroundColor = UIColor(red: 81/255, green: 139/255, blue: 91/255, alpha: 1).CGColor          

Upvotes: 1

Related Questions