Usually we are directly using similar to #EE1289这样的代码来直接表示RGB颜色的. But in the iOS language, its color representation is more alternative, he uses a 0-1 decimal to represent the color value. Such an implementation may be able to represent more color values, but it undoubtedly increases the amount of code for the program staff. When we get #EE1289时, this is usually called.
?
1 |
[UIColor colorWithRed:0xEE/255.0 green:0x12/255.0 blue:0x89/255.0 alpha:1]; |
This invocation is really cumbersome, so encapsulate a small method to call directly
?
1 2 3 4 5 6 |
/* * 获取颜色 */ +(UIColor *)colorWithRGB:( int )color alpha:( float )alpha{ return [UIColor colorWithRed:((Byte)(color >> 16))/255.0 green:((Byte)(color >> 8))/255.0 blue:((Byte)color)/255.0 alpha:alpha]; } |
When using the above method, the calling format is as follows:
?
1 |
[UIColor colorWithRGB:0xEE1289 alpha:1] |
Convenient for many.