【发布时间】:2020-09-06 13:17:43
【问题描述】:
我想在用户点击按钮时更改我的 UIBUtton 的标题颜色,如果用户按住按钮,当前 UIBUtton 标题的颜色会发生变化,但是在快速点击时不会更改,您能否让我知道我需要在下面的代码中更改哪些内容才能仅在点击检测时更改 titleColor:
var resetFiltersButton: UIButton = {
let button = UIButton(type: .system)
button.setTitle("Clear Filters", for: .normal)
button.titleLabel?.font = UIFont(name: "AppleSDGothicNeo-Bold", size: 20)
button.setTitleColor(.blue, for: .normal)
button.setTitleColor(.red, for: .highlighted)
button.titleLabel?.numberOfLines = 1
button.tag = 1
button.addTarget(self, action: #selector(buttonPressed(_:)), for: .touchUpInside)
button.translatesAutoresizingMaskIntoConstraints = false
return button
}()
@objc func buttonPressed(_ sender: UIButton) {
// MARK: - Clear Filters button pressed:
if sender.tag == 1 {
}
}
【问题讨论】:
标签: swift xcode colors uibutton title