UIButton: set image for selected-highlighted state

后端 未结 15 2802
花落未央
花落未央 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条回答
  •  猫巷女王i
    2020-11-28 19:44

    Swift 3+

    button.setImage(UIImage(named: "selected_image"), for: [.selected, .highlighted])
    

    OR

    button.setImage(UIImage(named: "selected_image"), for: UIControlState.selected.union(.highlighted))
    

    It means that the button current in selected state, then you touch it, show the highlight state.

提交回复
热议问题