1

I have this code:

myButton.setBackgroundImage(UIImage(named: "image1"), for: .normal)

I'm trying to add a background for the button from the code level. I would like to set the aspect fit to this background. At the moment, the background image is not displayed properly.

ZeMoon
  • 20,054
  • 5
  • 57
  • 98
trifd
  • 83
  • 1
  • 1
  • 7

1 Answers1

3
button.imageView?.contentMode = .scaleAspectFit

It will work..for Button's background Image

Wings
  • 2,398
  • 23
  • 46