簡體   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