How to restrict button click

前端 未结 3 1089
花落未央
花落未央 2021-01-27 18:10

I have a VC like this

for the checkBoxes i have embedded UIButtons and i am changing their image on click. Here\'s my code

@IBOutlet weak var be         


        
3条回答
  •  离开以前
    2021-01-27 18:49

    You could rename updateCheckImageOnClick(button: UIButton) to something generic in order to add some logic inside, like:

    func update(button: UIButton) {
        isBoxClicked = !isBoxClicked
    
        button.setImage(isBoxClicked ? UIImage(named: "checkmark") : UIImage(), for: UIControlState.normal)
    
        if button == bestSellerButton {
            trendingButton.isEnabled = false
            lowToHighButton.isEnabled = false
            highToLowButton.isEnabled = false
        } else if button == trendingButton {
            bestSellerButton.isEnabled = false
            lowToHighButton.isEnabled = false
            highToLowButton.isEnabled = false
        } else if button == highToLowButton {
            trendingButton.isEnabled = false
            lowToHighButton.isEnabled = false
            bestSellerButton.isEnabled = false
        } else {
            bestSellerButton.isEnabled = false
            trendingButton.isEnabled = false
            highToLowButton.isEnabled = false
        }
    }
    

提交回复
热议问题