0
我有一个UIButton,当点击时我想让它闪烁一段背景色,然后在一段时间后返回到原来的颜色。如何闪光颜色?
它的旧颜色不总是相同的,所以我做了一个类变量。
这里是我当前的代码,但我不知道如何实现延时:
class ViewController: UIViewController {
///stuff
var oldColor: UIColor?
@IBAction func buttonPressed(_ sender: UIButton) {
oldColor = sender.backgroundColor
flashColor(sender, UIColor.green)
}
func flashColor(btn: UIButton, color: UIColor) {
btn.backgroundColor = color
wait(100ms) //I really have no idea how to do this part
btn.backgroundColor = oldColor
}
}
你应该认真地把这个Github上要义!这太神奇了,谢谢,我会接受这一次,让我 –