简体   繁体   English

如何更改 UI Button 的标题文本颜色?

[英]How to change the title text color of UI Button?

I tried changing the colors of the text for a button, but it's still staying white.我尝试将文本的 colors 更改为按钮,但它仍然保持白色。 Please help me.请帮我。

isbeauty = UIButton()
isbeauty.setTitle("Buy", forState: UIControlState.Normal)
isbeauty.titleLabel?.textColor = UIColorFromRGB("F21B3F")
isbeauty.titleLabel!.font = UIFont(name: "AppleSDGothicNeo-Thin" , size: 25)
isbeauty.backgroundColor = UIColor.clearColor()
isbeauty.layer.cornerRadius = 5
isbeauty.layer.borderWidth = 1
isbeauty.layer.borderColor = UIColorFromRGB("F21B3F").CGColor
isbeauty.frame = CGRectMake(300, 134, 55, 26)
isbeauty.addTarget(self,action: "first:", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(isbeauty)

For example - white title text, gray when highlighted (tap is down):例如 - 白色标题文本,突出显示时为灰色(点击向下):

isbeauty.setTitleColor(.white, for: .normal)
isbeauty.setTitleColor(.gray, for: .highlighted)

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

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