【问题标题】:Enable tint color change animation when creating UIButton programmatically以编程方式创建 UIButton 时启用色调颜色更改动画
【发布时间】:2019-03-07 04:02:24
【问题描述】:

我没有使用 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 时,蓝色的文本会慢慢变为浅蓝色。不是突然的。

【问题讨论】:

    标签: ios swift


    【解决方案1】:

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

    试试这个:

    var button = UIButton(type: .system)
    

    【讨论】:

    • 正是我所需要的。谢谢!
    猜你喜欢
    • 2020-05-23
    • 1970-01-01
    • 2015-04-02
    • 1970-01-01
    • 1970-01-01
    • 2015-12-06
    • 2021-03-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多