【问题标题】:How to set the UIButton tint color of a system image when pressed?按下时如何设置系统图像的 UIButton 色调?
【发布时间】:2021-03-18 15:57:30
【问题描述】:

我有一个使用系统图标作为图像的 UIButton,此时我正在使用以下设置色调颜色

buttonLogin?.tintColor = Globals().buttonFontColor

现在,当我按下按钮时,突出显示的状态会将色调颜色更改为深灰色。我想改变它,这样当我按下按钮时,颜色可以由我设置。我尝试过将按钮子类化,但没有成功。

import UIKit

class CustomButton: UIButton {
    
    override open var isHighlighted: Bool {
        didSet {
            tintColor = isHighlighted ? UIColor.white : UIColor.green
        }
    }

    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}

谁能给我指出正确的方向谢谢。

【问题讨论】:

    标签: ios swift uibutton


    【解决方案1】:

    您还必须禁用调整图像属性:

    buttonLogin?.adjustsImageWhenHighlighted = false
    

    现在灰色效果应该消失了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-22
      • 1970-01-01
      • 1970-01-01
      • 2019-08-08
      • 2013-02-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多