coo*_*mac 106 uibutton ios swift
我尝试更改按钮的文本颜色,但它仍然保持白色.
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)
Run Code Online (Sandbox Code Playgroud)
我也试过把它改成红色,黑色,蓝色,但什么也没发生.
luk*_*302 238
您必须使用func setTitleColor(_ color: UIColor?, forState state: UIControlState)与设置实际标题文本相同的方式.文件
isbeauty.setTitleColor(UIColorFromRGB("F21B3F"), forState: .Normal)
Run Code Online (Sandbox Code Playgroud)
Vya*_*lav 101
Swift 3,Swift 4
改进评论.这应该工作:
Button(action: {}) {
Text("Button")
}.foregroundColor(Color(red: 1.0, green: 0.0, blue: 0.0))
Run Code Online (Sandbox Code Playgroud)
设置按钮标题颜色的示例
btnDone.setTitleColor(.black, for: .normal)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
103978 次 |
| 最近记录: |