我需要更改按钮文本的颜色.我还需要在用户按下后将状态更改为Disabled.
我不知道该怎么做.我一直在寻找一段时间,但他们都是客观的C或我无法理解它(通常帮助文档,他们是愚蠢的.).
小智 79
在swift中,使用setTitleColor方法更改特定状态的颜色.
在你的情况下,它将是:
button.setTitleColor(UIColor.grayColor, forState: UIControlState.Normal)
Run Code Online (Sandbox Code Playgroud)
Avi*_*Avi 34
改变文字的颜色
button.titleLabel.textColor = UIColor.grayColor()
Run Code Online (Sandbox Code Playgroud)
要更改状态,请在按钮上按添加以下项 -
button.enabled = true
Run Code Online (Sandbox Code Playgroud)
IBAction方法应该像 -
@IBAction func buttonTapped(sender : UIButton!) {
sender.enabled = false
}
Run Code Online (Sandbox Code Playgroud)
Mik*_*keJ 23
斯威夫特3
button.setTitleColor(UIColor.gray, for: UIControlState.normal)
Run Code Online (Sandbox Code Playgroud)
注意;
您必须为特定按钮状态设置文本颜色.
对于Swift3,请尝试以下代码:
@IBAction func butnClicked(sender : UIButton) {
sender.setTitleColor(.red, for: .normal)
sender.isEnabled = false
}
Run Code Online (Sandbox Code Playgroud)
Enabled
从故事板设置和文本颜色.
归档时间: |
|
查看次数: |
53797 次 |
最近记录: |