Swift: 删除一个 UIButton attributedTitle

Swift: Remove a UIButton attributedTitle

如果 UIButton 同时设置了标题和 attributedTitle,则显示的是 attributedTitle。

如果我将按钮设置为属性标题:

myButton.setAttributedTitle(myAttribText, for: .normal)

稍后在应用程序中我想将按钮设置为常规标题:

myButton.setTitle(myRegularText, for: .normal)

是否有一行代码可以用来删除按钮上的 attributedTitle,这样它就不会覆盖我为按钮设置的新标题?谢谢!

您需要先将 AttributedTitle 设置为 nil,然后再为您的按钮设置使用 setTitle,它的工作我已经检查过了。

像这样

myButton.setAttributedTitle(nil, for: .normal)
myButton.setTitle(myRegularText, for: .normal)