Search code examples
iosuicolor

UIColor Color with RGB never gets the right color


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];

Solution

  • 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.