skip to Main Content

I tried multiple solutions from stack overflow but no luck. I have set HighlightedAdjustsImage = false

In my Code :

button.backgroundColor = .clear
button.layer.borderWidth = 0

inside my IBAction for button I am changing image and also setting value of isSelected as :

button.isSelected = !button.isSelected

Inside storyboard enter image description here

what did i do wrong here?

3

Answers


  1. Try this

    To disable the highlighting effect of a UIButton when it is clicked, you can set its showsTouchWhenHighlighted property to false. Here’s how you can do it:

    yourButton.showsTouchWhenHighlighted = false
    
    Login or Signup to reply.
  2. To disable the highlighting effect of a UIButton ,
    please add the below extension in your code:

     class NoHighlightButton: UIButton {
        override var isHighlighted: Bool {
            get {
                return false
            }
            set {
                // Do nothing to prevent the default highlighting behavior
            }
        }
    }
    

    after that go to the interface builder and change the button class UIButton to NoHighlightButton. Your issue will be resolved.

    Login or Signup to reply.
  3. The problem is the Style setting of your button in the storyboard (the second popup menu in your screenshot).

    Change the Style from Plain to Default and the button will start working according to your specification.

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search