用自定义颜色扩展UIColor是真的吗? [英] Extension for UIColor with custom colors it is real?
本文介绍了用自定义颜色扩展UIColor是真的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用程序有一些自定义颜色,现在它像字典一样保存,但我认为这不是一个好主意,我想用自定义颜色对UIColor进行扩展。
I have some custom colors for my application and now its saves like a dictionary, but I think this is no really good idea and I want to do extension for UIColor with a custom color.
这可能看起来像这样
var newColor = UIColor.MyColor // like UIColor.white
也许我应该用扩展名添加我的颜色枚举?
Maybe I should add to extension an enumeration with my colors?
推荐答案
在UIColor扩展中创建类属性
Create class property in UIColor extension
extension UIColor
{
class var themeColor:UIColor {
return UIColor(red: 210.0/255.0, green: 105.0/255.0, blue: 130.0/255.0, alpha: 1.0)
}
}
OR
extension UIColor {
static let themeColor = UIColor(red: 210.0/255.0, green: 105.0/255.0, blue: 130.0/255.0, alpha: 1.0)
}
用法
self.view.backgroundColor = UIColor.themeColor
这篇关于用自定义颜色扩展UIColor是真的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文