Reputation: 385
I'm trying to make a clone of decimal pad by stack views and UIButtons. But when I try to make "Backspace" button image inside of it scales to the bounds of button.
How could I make image scale smaller than button itself?
Upvotes: 14
Views: 29752
Reputation: 3986
iOS 15
let button = UIButton()
var config = UIButton.Configuration.filled()
config.imagePadding = 40
button.configuration = config
return button
Upvotes: 2
Reputation: 1141
There may be two options to fix the problem.
Set the content mode to .scaleAspectFit and the image should not go out of the bounds :
myButton.imageView?.contentMode = .scaleAspectFit
Adjust the image insets:
myLikesButton.imageEdgeInsets = UIEdgeInsetsMake(top, left, bottom, right)
Upvotes: 16
Reputation: 163
Sanket was close:
**The (40, 40, 40, 40) is just an example button sizing and you can adjust it to your satisfaction. Like Sanket answered (Top, Left, Bottom, Right) is what you should use, just adjust with actual numbers.
Upvotes: 3
Reputation:
Things you should keep in mind while loading image to the 'UIBUTTON'
Upvotes: 0