skip to Main Content

I want to set an image to the button
enter image description here

But every time when I add an image to the button it shows a huge image and the image doesn’t fit the button size. Like this: enter image description here

2

Answers


  1. yourButton.clipsToBounds = true
    yourButton.contentMode = .scaleAspectFill
    
    // Use setBackgroundImage or setImage
    yourButton.setBackgroundImage(UIImage(named: "yourImage"), for: .normal)
    
    Login or Signup to reply.
  2. Change button style from ‘Plain’ to ‘Default’

    Click here for the image reference

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