Swift,按标签值更改UIButton颜色

时间:2015-02-01 18:36:15

标签: iphone xcode swift button colors

我试图改变UIButtons颜色,使用标签值,我有2个不同的代码,但它们都不起作用。

self.view.viewWithTag(Int(buttonNumber))?.backgroundColor = UIColor.blueColor()




var tempButton = self.view.viewWithTag(Int(buttonNumber)) as? UIButton

tempButton?.backgroundColor = UIColor.blueColor()

这些都不起作用,我也找不到如何解决这个问题

1 个答案:

答案 0 :(得分:0)

这对我有用:

var tempButton = self.view.viewWithTag(Int(buttonNumber)) as? UIButton
tempButton?.backgroundColor = UIColor.blue.withAlphaComponent(0.6)

我希望它有所帮助