2015-12-15 150 views
1

我不能將我的RGB顏色設置爲UINavigationBar和ToolBar。我試了一下如何將自定義(RGB)顏色設置爲導航欄?

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
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

0

UINavigationBar.appearance()barTintColor =的UIColor(紅色:73.0/255.0,綠色環保:155.0/255.0,藍:255.0/255.0 ,alpha:1.0)

相關問題