UIButton: set image for selected-highlighted state

后端 未结 15 2800
花落未央
花落未央 2020-11-28 19:23

I set an images for button\'s states Normal,Highlighted and Selected, but when the button in selected state and I press/highlight it I didn\'t see my highlighted image but j

15条回答
  •  盖世英雄少女心
    2020-11-28 19:29

    In my case, I have to change the UIButton.Type from .custom to .system

    And:

    button.setImage(UIImage(named: "unchecked"), for: .normal)
    button.setImage(UIImage(named: "checked"), for: [.selected, .highlighted])
    

    When handling tapping:

    button.isSelected = !button.isSelected

提交回复
热议问题