我正在尝试根据我在String中保存颜色的字典来更改几个UIButton的backgroundColor。
即
button1.backgroundColor = dic!.valueForKey("Button1Color") as? UIColor
// in the dictionary:
Button1Color = "UIColor.redColor()"
我没有。 为什么呢?
答案 0 :(得分:1)
您可以将颜色存储为字符串,并使用一些库或代码段(例如here)将其转换为Float
并返回字符串。
或者,您可以在类似于此的方案中存储构成UIColor的4个let bg1: [String:CGFloat] = ["red": 1, "green": 0, "blue": 0, "alpha": 1]
数字:
UIColor(red:green:blue:alpha)
并使用初始值设定项UIColor
创建UIColor
对象。
注意:这些是将数据持久化到磁盘的一些想法。显然,在仅在内存中数组中,您可以放置任何您喜欢的对象,包括df = pd.DataFrame( {'Stock' : ['Apple','Broadcomm','Citi','D&G'],
'PE' : pd.Series([1.5,3.9,5.6,6.8]),
})
。