【发布时间】:2017-06-26 12:47:44
【问题描述】:
我在mainStoryboard 上有一个UIButton。它具有白色UIColor 和橙色突出显示颜色。
我想在选择按钮后立即更改此按钮的颜色。
理想结果
White(default) -> orange(highlighted) -> green(animated) -> white(default)
但是,使用以下代码,在颜色从橙色变为绿色之前,它会很快变为白色。
当前结果
White(default) -> orange(highlighted) -> White(default) -> green(animated) -> white(default)
如何将颜色从突出显示的橙色直接切换为绿色?
UIView.animate(withDuration:0, animations: { () -> Void in
cell.buttons[index].backgroundColor = UIColor.green
}) { (Bool) -> Void in
UIView.animate(withDuration: 0.5, animations: { () -> Void in
cell.buttons[index].backgroundColor = UIColor.green
}, completion: { (Bool) -> Void in
UIView.animate(withDuration: 0, animations: { () -> Void in
cell.buttons[index].backgroundColor = UIColor.white
}, completion:nil)
})
}
【问题讨论】:
-
你的 UIButton 是什么类型的?确保它在情节提要中设置为自定义。
-
您使用什么方法为您的按钮获得橙色的“突出显示颜色”?