ios – Declare UIColor as a Variable in Swift

0
174


I need to declare a variable that represents the color of a button. This buttons color will change multiple times and will be loaded in at the start of the view. (The main issue is that I can not declare the color of a button once and then programmatically redeclare it to another color)

Original button declaration

var bttnBackgroundThemeVar0: UIColor = .red

Button later being redeclared as red

bttnBackgroundThemeVar0 = UIColor .green

Button color being set to bttnBackgroundThemeVar0

self.bttn1.backgroundColor = bttnBackgroundThemeVar0

When this code is executed the build “succeeds” however, “fails” when the view is executed. The following is the “fail” notification.

Thread 1: “*** -CGColor not defined for the UIColor <UIPlaceholderColor: 0x283d7ee00>; need to first convert colorspace.”