2014-07-07 22 views
2

我花了大約一個小時試圖弄清楚爲什麼我的BarTintColor在UINavigation欄中沒有改變。我猜你不能使用RGB來設置BarTintColor?有沒有解決方法?我想要能夠控制顏色。UINavigationBar BarTintColor不能使用RGB值

更新:

OK kambla幫了我很多。我把我的應用程序代理以下在

NSUInteger r = 228, g = 228, b = 228; 
    UIColor *color = 
     [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:0]; 
    [[UINavigationBar appearance] setBarTintColor:color]; 

    return YES; 

我證實,該代碼被執行「applicationdidFinishLaunchingWithOptions」的尾部。但我的導航欄上的色調不變?

+1

顯示你的代碼和閱讀'UIColor'文檔讓您瞭解它預計值。 – rmaddy

+0

'alpha:0'表示您創建一個完全透明的顏色(即不可見)。請注意,在我的答案中,我使用了alpha值「1.0」(完全不透明/不透明)。 – kambala

+0

我的錯誤。我試過alpha 1.0,它是一樣的。沒有什麼變化。我很難過。 –

回答

11

你必須255.0因爲UIColor預計0.0-1.0範圍內的值來劃分您的RGB值:

NSUInteger r = 127, g = 127, b = 127; 
UIColor *color = [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0]; 
+0

在您看到它之前,不要假設存在問題。 OP尚未發佈任何相關代碼。 – duci9y

+0

我同意你的意見。但這是一個相當常見的陷阱。 – kambala