Alexander Khitev
Alexander Khitev

Reputation: 6851

How to set custom (RGB) color to Navigation bar?

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?

Upvotes: 1

Views: 2195

Answers (2)

Avt
Avt

Reputation: 17043

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

enter image description here

Upvotes: 5

Gaurav Gudaliya
Gaurav Gudaliya

Reputation: 131

UINavigationBar.appearance().barTintColor = UIColor(red: 73.0 / 255.0, green: 155.0 / 255.0, blue: 255.0/ 255.0, alpha: 1.0)

Upvotes: 0

Related Questions