UIColor colorWithRed: green: blue: alpha: always returns white if only one argument is not 0

I use

[UIColor colorWithRed:136 green:155 blue:218 alpha:1.0]; 

to change the background color in the table view cells.

But for some reason, the background just remains white. If i try

[UIColor colorWithRed:0 green:155 blue:218 alpha:1.0]; 

color changes. It makes no sense to me. Any tips or advice?

+5
source share
3 answers

The parameter is not a value from 0 to 255, but a float between 0.0 and 1.0:

[UIColor colorWithRed:0.0f/255.0f green:155.0f/255.0f blue:218.0f/255.0f alpha:1.0f]; 
+33
source

Values ​​must be float (in the range of 0.0 to 1.0), not ints (in the range of 0 to 255).

+ (UIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha

Try:

[UIColor colorWithRed:136.0/255.0 green:155.0/255.0 blue:218.0/255.0 alpha:1.0]; 
+3
source

, , , , float 255. :

  [UIColor colorWithRed:136.0/255 green:155.0/255 blue:218.0/255 alpha:1.0];

That is why the color changes when you set red to 0 instead of 1, which in this case means 136.

+1
source

All Articles