选中时防止按钮图像突出显示 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选择时突出显示图像的颜色我不确定为什么会发生这种情况是按钮代码
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
}()
代码是 运行 xcode 10.2.1 使用 swift 4 和 iOS 12 部署
改变
UIButton(type: .system)
至
UIButton(type: .custom)
现在您可以完全控制按钮的外观和行为。
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选择时突出显示图像的颜色我不确定为什么会发生这种情况是按钮代码
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
}()
代码是 运行 xcode 10.2.1 使用 swift 4 和 iOS 12 部署
改变
UIButton(type: .system)
至
UIButton(type: .custom)
现在您可以完全控制按钮的外观和行为。