skip to Main Content

I’m just trying to set adjustsImageWhenDisabled = false. I get a deprecation warning but can’t find a simple solution. I can think of workarounds myself but this code adjustsImageWhenDisabled = false is just so simple and works.

My "image" is just an image made out of a color using UIGraphicsBeginImageContext. What I do now is that I override isEnabled and on didSet I set backgroundColor if disabled otherwise I use setBackgroundImage(for:) so that I get the highlighted effect when enabled.

And why does it not just work to use setBackgroundImage(for:.disabled)?

2

Answers


  1. Can you not try and set .disabled by setting the background image of the image.

    image.setBackgroundImage(disabledImage, for: .disabled)

    Login or Signup to reply.
  2. You are getting the deprecated warning with message like "This property is ignored when using UIButtonConfiguration…" so, you can still use it with UIButton otherwise use the configurationUpdateHandler like below:

    self.btn.configurationUpdateHandler = { button in
            switch button.state {
            case .disabled:
                button.imageView?.tintAdjustmentMode = .dimmed
                break
            default:
                button.imageView?.tintAdjustmentMode = .normal
                break
            }
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search