RGBColor宏定义16进制颜色码

当设计师标注十六进制颜色码的时候还需要去换算为 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))
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容