美文网首页iOS Developer
RGBColor宏定义16进制颜色码

RGBColor宏定义16进制颜色码

作者: 孟豊Mike | 来源:发表于2016-12-04 14:10 被阅读65次

    当设计师标注十六进制颜色码的时候还需要去换算为 RGB 值事件很费事的事,现在添加一个宏定义就可以快速使用十六进制颜色码,只需将#用0x代替写入就可以使用,附带快速设置 RGB 和 随机颜色宏定义代码

    /**
     *  宏定义16进制颜色代码 # 用 0x 代替
     */
    #define RGBColor(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
    
    /**
     * 宏定义16进制颜色代码带alpha
    透明度 # 用 0x 代替
     */
    #define RGBAColor(rgbValue, alphaValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:alphaValue]
    
    // RGB颜色
    #define MFColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
    
    // 随机色
    #define MFRandomColor MFColor(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256))
    

    相关文章

      网友评论

        本文标题:RGBColor宏定义16进制颜色码

        本文链接:https://www.haomeiwen.com/subject/thehmttx.html