繁体   English   中英

选择时防止按钮图像突出显示 swift 4

[英]Preventing button image highlight when selected swift 4

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 I am not确定为什么会发生这种情况是按钮代码

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 上运行

改变

UIButton(type: .system)

UIButton(type: .custom)

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM