我尝试更改按钮的文本颜色,但它仍然保持白色。
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/