I'd like to create a UIButton, but with a larger tap area than the image. (Ex: 40x40 button, but the image is only 20x20, centered).
Is that what imageEdgeInsets
is for?
I've set it both programatically: (This is in the UIView which contains my button)
- (void)awakeFromNib { [_plusButton setImageEdgeInsets:UIEdgeInsetsMake(10, 10, 10, 10)]; [_plusButton setContentMode:UIViewContentModeCenter]; }
And from storyboard
But neither of them seem to work.
You must set the content mode for the image inside the UIButton. The solution is to update the contentMode of the Image when you are using a foreground image inside a button along with the contentMode of the UIButton .
Returns a string formatted to contain the data from an edge insets structure. class func uiEdgeInsets(for: String) -> UIEdgeInsets. Returns a UIKit edge insets structure based on the data in the specified string.
The rule when it comes to titleEdgeInsets or imageEdgeInsets is to add equal and opposite offsets to the left and right insets. So if you add for example 8 points to the left title inset, you need to apply -8 points to the right inset.
Got it I think that you set your image as a background image of the button, set it as a image then it will never stretches(remains in it original shape) and imageEdgeInsets
will works on it properly.
Like:
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