Monday, June 13, 2011

How to Create UIColor with RGB Values ?

It is very much possible to convert the RGBA values to UIColor, you don't have to keep using standard [UIColor redColor] or [UIColor greenColor]. You can create your own color with your own RGB values.

    CGFloat nRed=128.0/255.0;
    CGFloat nBlue=98.0/255.0;
    CGFloat nGreen=53.0/255.0;
    UIColor *myColor=[[UIColor alloc]initWithRed:nRed green:nBlue blue:nGreen alpha:1];

Note: The value of red, green,blue and alpha will be between 0 and 1. Also if you can reduce the value of alpha to be something like 0.3 or 0.5 as long as it is between 0 and 1, to manipulate the transparency.


  1. Just noticed a mistake in your sample. When you set nBlue you need to set it to 98.0/255.0 (yours is just 98). Otherwise it will be interpreted as 0 and throw off your color.

  2. CGFloat nRed=25.0/255.0;
    CGFloat nGreen=34.0/255.0;
    CGFloat nBlue=53.0/255.0;

    UIColor *myColor=[[UIColor alloc]initWithRed:nRed green:nGreen blue:nBlue alpha:1];

    more user friendly if you can change above ..

  3. your blogs is awesome.
    4G internet Service
    Videocon Telecom to rollout 4G services in UPE, UPW & Bihar Telecom circles. Plans to utilize the entire spectrum for 4G LTE FDD rollout on 1800 Mhz band in select cities & offer voice on overlay Network.