Ios 如何更改UIButton的属性文本颜色?

Ios 如何更改UIButton的属性文本颜色?,ios,swift,Ios,Swift,我想更改UIButton在选中和正常状态下的属性标题颜色,问题是它在选中状态下不工作 以下是代码:- func setColorForBtn(_ color:UIColor,_ state:UIControlState) { let myAttributedTitle = NSAttributedString(string: "Click Here", attributes: [N

我想更改UIButton在选中和正常状态下的属性标题颜色,问题是它在选中状态下不工作

以下是代码:-

func setColorForBtn(_ color:UIColor,_ state:UIControlState) { let myAttributedTitle = NSAttributedString(string: "Click Here", attributes: [NSAttributedStringKey.foregroundColor : color]) myButton.setAttributedTitle(myAttributedTitle, for: state) } func setColorForBtn(color:UIColor,state:UIControlState){ 让myAttributedTitle=NSAttributedString(字符串:“单击此处”, 属性: [NSAttributedStringKey.foregroundColor:color]) myButton.SetAttributeTitle(MyAttributeTitle,for:state) }
我在iOS开发方面也很新,但为什么不使用它们来设置某些特定状态的按钮标题和标题颜色呢

myButton.setTitle(title, for: state)
myButton.setTitleColor(color, for: state)

你的问题是什么?问题是…你面临的问题是什么?问题是当选择状态时,它会显示白色,而不是我想设置的颜色伙计们,你知道吗?我设置的是“setAttributedTitle”而不是“setTitle”,所以它们之间有很大的区别是的,正如你所说的,有很大的区别,但是如果你只改变颜色和文本,使用它有什么意义呢?我只想显示我的按钮被选中和未被选中。但该文本是属性化的(按钮标题)。