I've in a database a few rows where one field is ARGB value for the related color.
I've to read all the rows of these table and convert the ARGB value decimal to a UIColor.
I've googled finding this, but I didn't.
Is there any way to approach this?
Thanks.
Here's the method I came up with to convert an ARGB integer into a UI color. Tested it on several colors we have in our .NET system
+(UIColor *)colorFromARGB:(int)argb {
int blue = argb & 0xff;
int green = argb >> 8 & 0xff;
int red = argb >> 16 & 0xff;
int alpha = argb >> 24 & 0xff;
return [UIColor colorWithRed:red/255.f green:green/255.f blue:blue/255.f alpha:alpha/255.f];
}
text.color = [UIColor colorWithRed:10.0/255.0 green:100.0/255.0 blue:55.0/255.0 alpha:1];
You just need to divide the RGB values by 255 to get things to set up correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With