I have a UIButton with a "custom" type, with an "image" property that gets its image from resources. The image is smaller than the button. I cannot achieve into Interface Builder to keep the original size of the image while scaling the button's dimensions as I want.
How may I have a button of any size into IB, keeping the original image size, aligning it on center, left right, bottom, inot the button... ? Isn't it possible without putting a UIImageView on it ?
Make sure that the contentHorizontalAlignment
and contentVerticalAlignment
properties of your button are not set to UIControlHorizontalAlignmentFill
and UIControlVerticalAlignmentFill
respectively. Those values will scale the button image to fill the button frame. Any other value will align the image appropriately.
Use image foreground to put non-resizable image elements, found in a post on stackoverflow but forget where it is.
button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
button.imageEdgeInsets = UIEdgeInsetsMake(0,-10,0,0);
[button setImage:[UIImage imageNamed:@"back-button"] forState:UIControlStateNormal];
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