Why does a custom UIButton image not resize with the button?
I set its view mode to Scale to Fill in Interface Builder, but unlike a UIImageView image, it doesn't respect that setting.
Am I looking in the wrong place or is it not possible?
Using storyboard, select the button, then in the size inspect click the dropdown on size just above Content inset. There is a list of sizes to select from, and this will adjust your image size(if you use system image). The default size is already set when you added the button on the storyboard to the View Controller.
A control that executes your custom code in response to user interactions.
It is a control that enables the user to interact with the application. It is used to trigger the events performed by the user. It executes the custom code in response to user interactions. class UIButton : UIControl.
While this may not be quite what you're after - the background image does scale.
Try this:
[button setImage:image forState:UIControlStateNormal]; button.contentVerticalAlignment = UIControlContentVerticalAlignmentFill; button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill;
In Swift:
button.contentVerticalAlignment = .fill button.contentHorizontalAlignment = .fill
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With