ios - 如何设置UIButton的标题文字颜色?

标签 ios swift uibutton

我尝试更改按钮的文本颜色,但它仍然保持白色。

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)

我也尝试将其更改为红色、黑色、蓝色,但没有任何反应。

最佳答案

您必须像设置实际标题文本一样使用 func setTitleColor(_ color: UIColor?, for state: UIControl.State)Docs

isbeauty.setTitleColor(UIColorFromRGB("F21B3F"), for: .normal)

关于ios - 如何设置UIButton的标题文字颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31088172/

相关文章:

iphone - 如何向 ScrollView 添加渐变?

ios - 阻止 UIView 离开屏幕

swift - 获取进程的所有打开文件导致 errno 12 = Out of Memory

iOS UIButton - UIButton setUserInteractionEnabled 和 setEnabled 之间的区别

iphone - 我在哪里可以获得精美的红色和绿色 UIButtons 之类的 "End Call"等?

ios - 在某些 XCode/Mac OS 上面临 PNGCrush 问题(不具体)

ios - 如何创建 2 步可扩展的 tableview Swift

ios - swift 3 在tableView 中按下了哪个单元格按钮

ios - 从 Modal/Popover 展开 Segue,导致对开始/结束外观转换的调用不平衡

ios - UILabel高度计算