iOS --- UIColor中使用16进制选取颜色
iOS中的UIColor能够使用16进制来选取颜色.
预先定义例如以下:
#define UIColorFromHex(s)
[UIColor colorWithRed:(((s & 0xFF0000) >> 16))/255.0
green:(((s & 0xFF00) >> 8))/255.0
blue:((s & 0xFF))/255.0 alpha:1.0]
用法:
view.backgroundColor = UIColorFromHex(0xdcdcdc);
假设要使用RGB格式呢?
#define RGBCOLOR(r,g,b)
[UIColor colorWithRed:r/255.f
green:g/255.f
blue:b/255.f
alpha:1.f]
#define RGBCOLOR(r,g,b,a)
[UIColor colorWithRed:r/255.f
green:g/255.f
blue:b/255.f
alpha:a]
用法:
btn.backgroundColor = RGBCOLOR(33, 33, 33);