Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 更改UIButton中标题的背景色_Ios_Swift_Uibutton_Uibackgroundcolor - Fatal编程技术网

Ios 更改UIButton中标题的背景色

Ios 更改UIButton中标题的背景色,ios,swift,uibutton,uibackgroundcolor,Ios,Swift,Uibutton,Uibackgroundcolor,我想更改UIButton中标题的背景色(仅限!),其中包含标题和图像 我只能看到如何改变整个按钮的背景色,这不是我想要的 有什么想法吗?您需要设置标题标签的背景色: btn.titleLabel?.backgroundColor = UIColor.red 您需要设置标题标签的背景色: btn.titleLabel?.backgroundColor = UIColor.red 要更改按钮标题颜色,请执行以下操作: btn.setTitleColor(UIColor.yourColor, fo

我想更改UIButton中标题的背景色(仅限!),其中包含标题和图像

我只能看到如何改变整个按钮的背景色,这不是我想要的


有什么想法吗?

您需要设置标题标签的背景色:

btn.titleLabel?.backgroundColor = UIColor.red

您需要设置标题标签的背景色:

btn.titleLabel?.backgroundColor = UIColor.red

要更改按钮标题颜色,请执行以下操作:

btn.setTitleColor(UIColor.yourColor, for: .normal)

要更改按钮标题颜色,请执行以下操作:

btn.setTitleColor(UIColor.yourColor, for: .normal)
答案是:

 btn.tintColor = UIColor.clear  //if we have different tint, which I had 
 btn.titleLabel?.backgroundColor = UIColor.clear
答案是:

 btn.tintColor = UIColor.clear  //if we have different tint, which I had 
 btn.titleLabel?.backgroundColor = UIColor.clear

最后应该是什么样子?你试过设置函数了吗?像这样-btnLogin.set……….使用NSAttributedStrings@Larme-由于色调不同,我可以在标题中看到与整个按钮不同的背景色,这很难看。我只想将标题的背景设置为清晰。我不太明白你的意思,但是你可以通过使用UIButton上的
setTitleColor(.red,for:.normal)
函数来更改标题标签的颜色,最后它应该是什么样子?你试过set函数了吗?像这样-btnLogin.set……….使用NSAttributedStrings@Larme-由于色调不同,我可以在标题中看到与整个按钮不同的背景色,这很难看。我只想将标题的背景设置为清晰。我不知道你的真正意思,但你可以使用UIButton上的
setTitleColor(.red,for:.normal)
函数只更改标题标签的颜色这是正确的答案。我还必须添加btn.tintColor=UIColor.clear来删除色调。这是正确的答案。我还必须添加btn.tintColor=UIColor.clear以删除色调。这将设置字体颜色,而不是背景。这将设置字体颜色,而不是背景。