-3

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

  • Do you want a Title ***and*** an Image? Or just the image? – DonMag Nov 30 '22 at 18:22
  • Just an image without a title – Rustin Wilde Dec 01 '22 at 11:29
  • You would help yourself by going through some of the basics... In the project you posted, your Stack View has no constraints... you gave your buttons Width and Height constraints in Storyboard, and then you try to give them new constraints in code... you're using the newer "Configuration" buttons in Storyboard, but then using non-configuration methods in code (`.setTitle(...)` / `.setImage(...)` / etc)... you want image only, but you're also setting a Title string... and so on. All of those issues are conflicts which will continue to cause problems. – DonMag Dec 01 '22 at 12:45

2 Answers2

0
yourButton.clipsToBounds = true
yourButton.contentMode = .scaleAspectFill

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

Change button style from 'Plain' to 'Default'

Click here for the image reference