我使用的UIColor colorWithRed:綠:藍:阿爾法:除非一個參數是0
[UIColor colorWithRed:136 green:155 blue:218 alpha:1.0];
改變我的表視圖單元格的背景色總是返回白色。
但由於某種原因背景只是保持白色。如果我嘗試
[UIColor colorWithRed:0 green:155 blue:218 alpha:1.0];
顏色變化。這對我沒有意義。任何建議或提示?
我使用的UIColor colorWithRed:綠:藍:阿爾法:除非一個參數是0
[UIColor colorWithRed:136 green:155 blue:218 alpha:1.0];
改變我的表視圖單元格的背景色總是返回白色。
但由於某種原因背景只是保持白色。如果我嘗試
[UIColor colorWithRed:0 green:155 blue:218 alpha:1.0];
顏色變化。這對我沒有意義。任何建議或提示?
參數不爲0到255之間的值,但在0.0和1.0之間的浮動:
[UIColor colorWithRed:0.0f/255.0f green:155.0f/255.0f blue:218.0f/255.0f alpha:1.0f];
這些值需要浮點數(範圍爲0.0到1.0),而不是整數(範圍從0到255)。
+ (UIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha
嘗試:
[UIColor colorWithRed:136.0/255.0 green:155.0/255.0 blue:218.0/255.0 alpha:1.0];
的PARAMS不是整數而是漂浮,所以 你可能想要用255分割所有的彩色浮點值。 像這樣:
[UIColor colorWithRed:136.0/255 green:155.0/255 blue:218.0/255 alpha:1.0];
這就是爲什麼當您將紅色設置爲0而不是1時,顏色會發生變化,這在這種情況下表示爲136。
這樣的設計在早期的Mac OS X中一直回到Quartz,並且這個想法是提供完美的面向未來的設備無關色彩空間。 –
f在155.0f – Armand
f中做出的區別是155.0應該被解釋爲float而不是double。 – Luke