Skip to content

Instantly share code, notes, and snippets.

@zwf
Forked from ralfebert/UIColorFromRGB.h
Created December 4, 2013 13:05
Show Gist options
  • Save zwf/7787138 to your computer and use it in GitHub Desktop.
Save zwf/7787138 to your computer and use it in GitHub Desktop.
// For example:
// UIColorFromRGBA(0xffee00, 0.5)
// UIColorFromRGB(0xffee00)
static inline UIColor *UIColorFromRGBA(int rgb, float a) {
return [UIColor colorWithRed:((float)((rgb & 0xFF0000) >> 16))/255.0
green:((float)((rgb & 0xFF00) >> 8))/255.0
blue:((float)(rgb & 0xFF))/255.0 alpha:a];
}
static inline UIColor *UIColorFromRGB(int rgb) {
return UIColorFromRGBA(rgb, 1.f);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment