gpt4 book ai didi

ios11 - Swift 4 按钮淡入淡出

转载 作者:行者123 更新时间:2023-12-04 02:00:17 25 4
gpt4 key购买 nike

按下按钮时如何淡入淡出。

我正在寻找最简单和最佳实践的 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

我有点失落。非常感谢您的回答。

最佳答案

我不知道计算器的淡入/淡出,但你会得到类似的效果:

将 UIButton 类型设置为自定义,并将 Storyboard 中的文本颜色设置为白色。

enter image description here

将 UIButton 的 BackgroundColor 设置为 Tungsten(以计算器应用为例)

enter image description here

为 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)
}
}
}

结果:

enter image description here

关于ios11 - Swift 4 按钮淡入淡出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47732847/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com