尝试使用Swift3通过数组更改标签的颜色

时间:2017-04-13 07:23:20

标签: arrays swift3 uicolor

我正在开发一个测验应用程序,我正在屏幕上显示标签和几个按钮。我有一个数组,其中包含标签和按钮的问题和答案。向用户显示一个颜色的单词,用户应该单击与该颜色的单词对应的按钮。但是每次在问题内部更改时,我都找不到改变标签颜色的方法。阵列。

这是我的编码:

Colors = [Color (Color: (UIColor.red("Red")), Answers: ["Red","Blue","Yellow","Green"], Answer: 0 ),
                  Color(Color: "Blue", Answers: ["Red","Blue","Yellow","Green"], Answer: 1 ),
                  Color(Color: "Green", Answers: ["Red","Blue","Yellow","Green"], Answer: 3 ),
                  Color(Color: "Yellow", Answers: ["Red","Blue","Yellow","Green"], Answer: 2 )]

UIColor.red(" Red")根据快速语言错误

1 个答案:

答案 0 :(得分:1)

最简单的解决方案是将颜色属性的类型从UIColor更改为String,然后你就可以了。

Colors = [Color(Color: UIColor.red, Answers: ["Red","Blue","Yellow","Green"], Answer: 0 ),
              Color(Color: UIColor.blue, Answers: ["Red","Blue","Yellow","Green"], Answer: 1 ),
              Color(Color: UIColor.green, Answers: ["Red","Blue","Yellow","Green"], Answer: 3 ),
              Color(Color: UIColor.yellow, Answers: ["Red","Blue","Yellow","Green"], Answer: 2 )]