使用16进制颜色值

来源:互联网 发布:模拟开车的软件 编辑:程序博客网 时间:2024/06/08 16:13

通常情况下我们是直接使用类似于#EE1289这样的代码来直接表示RGB颜色的

 

[UIColor colorWithRed:0xEE/255.0 green:0x12/255.0 blue:0x89/255.0 alpha:1];

这样调用真是太繁琐了,所以封装了一个小方法来直接调用


/*

 *  获取颜色

 */

+(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];

}

使用以上方法的时候,调用格式如下:

  

[UIColor colorWithRGB:0xEE1289 alpha:1]





出处:http://www.2cto.com/kf/201405/303225.html

0 0