iOS --- UIColor中使用16进制选取颜色

Posted zhchoutai

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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);

以上是关于iOS --- UIColor中使用16进制选取颜色的主要内容,如果未能解决你的问题,请参考以下文章