【发布时间】:2020-05-06 20:51:15
【问题描述】:
以编程方式添加UIButton 时遇到问题。没有“点击动画”。
有谁知道为什么会发生这种情况以及如何解决这个问题?我找不到有关此主题的任何内容...
let weiterButton: UIButton = {
let v = UIButton()
v.translatesAutoresizingMaskIntoConstraints = false
v.setTitle("WEITER", for: .normal)
v.titleLabel?.font = UIFont(name: "AvenirNext-Bold", size: 20)
v.titleLabel?.textColor = .white
v.backgroundColor = UIColor(red: 75/255, green: 75/255, blue: 75/255, alpha: 1)
v.addTarget(self, action: #selector(weiterButtonTapped), for: .touchUpInside)
return v
}()
我想要的动画:
【问题讨论】:
-
您是否尝试为突出显示/按下的状态应用颜色?
-
没有。我只想要标准的点击动画。添加
backgroundImage时似乎可以正常工作,但我也想要没有image的动画 .. -
@TejaNandamuri 是对的。您需要为突出显示的状态添加自定义文本颜色,例如只需添加这一行
v.setTitleColor(.red, for: .highlighted) -
但应该更改
backgroundColor而不是TitleColor。 -
@AlexSmet 我用视频更新了我的问题
标签: ios swift animation uibutton