我正试图为我的iOS应用实施色盲模式。现在,我有3个全局变量,红色,绿色和蓝色定义如下:
var red : UIColor = UIColor(...)
var green : UIColor = UIColor(...)
var blue : UIColor = UIColor(...)
现在,我有一个UIButton,用户可以按此按钮更改为色盲模式。一旦发生这种情况,我就会改变全局变量:
red = newRed
green = newGreen
blue = newBlue
但是,这不会更新已加载的任何现有视图的颜色。有没有办法让我更新所有红色到新红色,绿色到新绿色,蓝色到新蓝色的控件,而无需重新加载整个应用程序?谢谢!
更新以发布我的按钮操作:
func changeColor(sender: AnyObject) {
red = UIColor(...) //this is different from the previous red
green = UIColor(...) //this is different from the previous green
blue = UIColor(...) //this is different from the previous blue
//if I call viewDidLoad() again, then the colors are changed for all objects. However, I don't think this is the correct thing to do.
}
答案 0 :(得分:1)
永远不要直接致电viewDidLoad()
。您需要确保IBOutlet
已附加到视图控制器内的视图中。此外,请确保直接更改视图的backgroundColor
属性。例如:
myView.backgroundColor = UIColor.redColor()