我尝试更改按钮文本的颜色,但仍然保持白色。
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: UIControlState)与设置实际标题文本相同的方式。文件
func setTitleColor(_ color: UIColor?, for state: UIControlState)
isbeauty.setTitleColor(UIColorFromRGB("F21B3F"), for: .normal)