简体   繁体   English

如何在 Swift 中更改按钮标题的颜色

[英]How to change the color of the button title in Swift

Is-it possible to change the color of the Title for the button ?是否可以更改按钮标题的颜色?

Because this code d'ont work因为这段代码不起作用

btnLogin.titleColor = UIColor.darkGray

尝试这个:

btnLogin.setTitleColor(.red, for: .normal)

As the other comments says, use正如其他评论所说,使用

    btnLogin.setTitleColor(UIColor.darkGray, for: .normal)

Here you can read the explanation of this method and the different states (normal, selected, highlighted, ...)在这里您可以阅读此方法的说明和不同状态(正常、选中、突出显示、...)

https://developer.apple.com/documentation/uikit/uibutton/1623993-settitlecolor https://developer.apple.com/documentation/uikit/uibutton/1623993-settitlecolor

你可以这样设置:

button.setTitleColor(.blue, for: .normal)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM