1
我有UIButton
在mainStoryboard
。它有白色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的类型是什么?确保它在故事板中设置为自定义。 –
你用什么方法为你的按钮获得橙色的“高亮颜色”? – DonMag