Last Updated: February 25, 2016
·
983
· esromneb

RBG on iOS the correct way

#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

Normal people think in hex color codes (so does photoshop) this helpful macro will make your life easy. Use it like this with the full hex color code and no quotes or anything:

segmentedControl.tintColor = UIColorFromRGB(0x56be8c);

1 Response
Add your response

I also captured this in a RGBX and RGBXA macro as part of MNColorKit available as a CocoaPod at https://github.com/madninja/MNColorKit in case it's of use to anyone

over 1 year ago ·