gpt4 book ai didi

ios - 以编程方式创建 UIButton 时启用色调颜色更改动画

转载 作者:行者123 更新时间:2023-11-28 11:45:45 24 4
gpt4 key购买 nike

我没有使用 Storyboard 来创建我的 UI,所以我像这样创建了我的按钮

var randomButton: UIButton = {
var button = UIButton()
button.translatesAutoresizingMaskIntoConstraints = false
button.setTitle("Random", for: .normal)
button.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.6)
button.layer.cornerRadius = 3
button.layer.borderWidth = 1
button.layer.borderColor = UIColor.black.cgColor
button.setTitleColor(.black, for: .highlighted)

button.addTarget(self, action: #selector(HomeController.buttonPressed), for: .touchUpInside)

return button
}()

问题是,当用户点击按钮时,色调颜色之间没有很好的过渡/动画。除非用户按住按钮,否则文本的颜色不会变为黑色。

正常行为,当您使用 Storyboard 时,蓝色文本会慢慢变为浅蓝色。不是突然。

最佳答案

我认为您所指的动画是系统类型按钮的一部分。

试试这个:

var button = UIButton(type: .system)

关于ios - 以编程方式创建 UIButton 时启用色调颜色更改动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52601360/

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