Home > Net >  How to set an image to the UIButton in Swift
How to set an image to the UIButton in Swift

Time:12-01

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

CodePudding user response:

yourButton.clipsToBounds = true
yourButton.contentMode = .scaleAspectFill

// Use setBackgroundImage or setImage
yourButton.setBackgroundImage(UIImage(named: "yourImage"), for: .normal)

CodePudding user response:

Change button style from 'Plain' to 'Default'

Click here for the image reference

  • Related