【发布时间】:2017-03-27 16:21:56
【问题描述】:
我阅读了一些文章,但没有找到解决我问题的解决方案。目前我正在用 Swift 3 构建一个 iOS 应用程序。我在视图中放置了一个名为 registerButton 的 UIButton。如果有人触摸按钮,则会出现一个新的 ViewController(newController)。除此之外,当用户触摸按钮并按住它时,应该更改 registerButton.textlabel.setColor() 的颜色吗? newController 的显示有效,但 textLabel 的更改颜色无效。我在注册函数中更改了 registerButton 的颜色。有人有想法吗?谢谢
var registerButton: UIButton = {
let button = UIButton(type: .system)
button.setTitle("Registration", for: .normal)
button.setTitleColor(UIColor.white, for: .normal)
button.addTarget(self, action: #selector(registration), for: .touchUpInside) // Action
return button
}()
func registration(){
let color = UIColor(r: 255, g: 0, b: 102)// red
registerButton.setTitleColor(color, for: .highlighted)
let newController = ViewController()
present(newController, animated: true, completion: nil)
}
【问题讨论】:
-
您想在按下按钮时更改按钮文本的文本颜色。对吧??
-
@Md.易卜拉欣·哈桑 没错!我想在按下按钮时更改按钮的颜色。如果我使用状态 .touchDown (@dfd 提到),则无法按住按钮。新的 ViewController 立即出现。