如何将自定义(RGB)颜色设置为导航栏?

时间:2015-12-15 10:46:39

标签: ios swift uinavigationcontroller uinavigationbar uicolor

我无法将RGB颜色设置为UINavigationBar和ToolBar。我试过了

  let myColor = UIColor(red: 47, green: 206, blue: 255, alpha: 1.0)
  self.navigationController?.navigationBar.barTintColor = myColor
  self.navigationController?.toolbar.tintColor = myColor

我也试过HSB颜色

let secondColor = UIColor(hue: 194, saturation: 82, brightness: 100, alpha: 1.0)
self.navigationController?.navigationBar.barTintColor = secondColor
self.navigationController?.toolbar.tintColor = secondColor

但是当我编写以下方法时,它可以工作。

self.navigationController?.navigationBar.barTintColor = UIColor.greenColor()
self.navigationController?.toolbar.tintColor = UIColor.greenColor()

如何将RGB颜色设置为条形?

2 个答案:

答案 0 :(得分:3)

let myColor = UIColor(red: 47, green: 206, blue: 255, alpha: 1.0)

不正确。 UIColor需要0.0 ... 1.0范围内的颜色分量。所以你可能需要

let myColor = UIColor(red: 47.0/255.0, green: 206.0/255.0, blue: 255.0/255.0, alpha: 1.0)

来自UIColor docs

enter image description here

答案 1 :(得分:0)

UINavigationBar.appearance()。barTintColor = UIColor(红色:73.0 / 255.0,绿色:155.0 / 255.0,蓝色:255.0 / 255.0,alpha:1.0)