UIColor RGB color never gets the right color

I'm trying to learn iOS, but I'm using + (UIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha

I always do not get the right number, always something is missing.

Please, help..

here is my code:

[UIColor colorWithRed:65/255 green:62/255 blue:125/255 alpha:1.0];
+4
source share
2 answers

easily...

you just need to add .0 at the end of each number, for example:

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

since they need a float instead of an int.

+11
source

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];
+1
source

Source: https://habr.com/ru/post/1526849/


All Articles