按下按钮时如何淡入和淡出。
我正在寻找尽可能最简单和最佳实践的 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
我有点迷失了。非常感谢您的回答。
最佳答案
我不知道计算器的淡入/淡出,但你会得到类似的效果:
从 Storyboard 中将 UIButton 类型设置为自定义并将文本颜色设置为白色。
将UIButton的BackgroundColor设置为Tungsten(以计算器应用程序为例)
为 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)
}
}
}
结果:
关于ios11 - Swift 4 按钮淡入、淡出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47732847/