如何更改 UIButton 的背景颜色?

Posted

技术标签:

【中文标题】如何更改 UIButton 的背景颜色?【英文标题】:How to change the background color of an UIButton? 【发布时间】:2021-11-04 08:35:57 【问题描述】:

我正在尝试做一些非常简单的事情,为了美观而更改 UIButton 的背景...但我找不到背景属性,因为其他所有按钮似乎都很清晰(没有明确的背景颜色)

func updateNewButton() 
    if newButton == true 
        let buttonFont = self.ButtonFont

        self.subscribeButton.SetAttributedTitle(title: StoreKit.sharedInstance.ButtonStateText, withFont: buttonFont, textColor: storeBackground, for: .normal)
    

【问题讨论】:

这能回答你的问题吗? change the background color of the title in UIButton 【参考方案1】:

更改UIButton的背景颜色:

self.subscribeButton.backgroundColor = .yourDesiredColor

要更改UIButtontitleLabel 的背景颜色:

self.subscribeButton.titleLabel?.backgroundColor = .yourDesiredColor

【讨论】:

以上是关于如何更改 UIButton 的背景颜色?的主要内容,如果未能解决你的问题,请参考以下文章