Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIColor Color with RGB never gets the right color

Tags:

ios

uicolor

i am trying to learn iOS developing, but i using + (UIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha

I always not getting the right number, it always like something missing..

Please help..

here is my code:

[UIColor colorWithRed:65/255 green:62/255 blue:125/255 alpha:1.0];
like image 864
user3282412 Avatar asked Dec 16 '22 01:12

user3282412


2 Answers

easy...

you simply need to add .0 at the end of each number, like this:

[UIColor colorWithRed:65.0/255.0 green:62.0/255.0 blue:125.0/255.0 alpha:1.0];

since they need Float value instead of int.

like image 197
Xu Yin Avatar answered Jan 01 '23 13:01

Xu Yin


Use this and add .0f after each parameter

[UIColor colorWithRed:65.0f/255.0f green:62.0f/255.0f blue:125.0f/255.0f alpha:1.0f];
like image 27
Gajendra Rawat Avatar answered Jan 01 '23 12:01

Gajendra Rawat