按下按钮时如何淡入和淡出。
我正在寻找最简单和最佳实践的Swift 4解决方案。
类似Apple iOS 11计算器按钮的东西会消失...
到目前为止,我有这个......
myButton.setTitleColor(UIColor.red, for: UIControlState.normal)
myButton.backgroundColor=UIColor.gray
myButton.setTitleColor(UIColor.gray, for: UIControlState.highlighted)
myButton.backgroundColor=UIColor.red
我有点失落。非常感谢你的回答。
答案 0 :(得分:3)
我不知道计算器的淡入/淡出但你会得到类似的效果:
将UIButton类型设置为自定义,并从故事板中将文本颜色设置为白色。
将UIButton的BackgroundColor设置为Tungsten(例如拿计算器app)
为UIButton创建自定义类,并从Identity Inspector 将customButton类设置为UIButton。
class customButton: UIButton {
override open var isHighlighted: Bool {
didSet {
//Set colors for Highlighted & Unhighlighted
backgroundColor = isHighlighted ? UIColor.lightGray.withAlphaComponent(0.7) : UIColor(red: 51/255, green: 51/255, blue: 51/255, alpha: 1.0)
}
}
}
结果: