【问题标题】:Preventing button image highlight when selected swift 4选择swift 4时防止按钮图像突出显示
【发布时间】:2020-11-29 13:46:27
【问题描述】:

I do my swift project using code only no storyboards, so no storyboard solutions please I have an agree to terms button and when selected the checkmark is covered in the tint color I am trying to prevent the tint color highlighting the image when selected我不确定为什么会发生这种情况是按钮代码

let agreeToTermsAndConditions : UIButton = {
    let button = UIButton(type: .system)
    button.tintColor = .gray
    button.backgroundColor = .white
    button.adjustsImageWhenHighlighted = false  
    button.setImage(UIImage(named:"unchecked" )!, for: .normal)
    button.setImage(UIImage(named:"agreechecked" )!, for: .selected)
    button.addTarget(self, action: #selector(userAgreedToTerms), for: .touchUpInside)
    
    return button
}()

代码使用 swift 4 和 iOS 12 部署在 xcode 10.2.1 上运行

【问题讨论】:

    标签: swift xcode10 ios12


    【解决方案1】:

    改变

    UIButton(type: .system)
    

    UIButton(type: .custom)
    

    现在您可以完全控制按钮的外观和行为。

    【讨论】:

      猜你喜欢
      • 2011-10-26
      • 2017-01-25
      • 2019-03-02
      • 2018-09-29
      • 1970-01-01
      • 1970-01-01
      • 2016-10-27
      • 1970-01-01
      • 2017-02-24
      相关资源
      最近更新 更多