IPhone - UIButton with no resized image inside

I have a UIButton with a "custom" type, with the "image" property, which gets its image from resources. The image is smaller than the button. I cannot reach the Builder interface to keep the original image size while scaling the button sizes as I want.

How can I use a button of any size in IB, keeping the original size of the image, aligning it in the center, from left to right, from below, inside the button ...? Is it possible without using UIImageView?

+5
source share
2 answers

Make sure that the properties contentHorizontalAlignmentand contentVerticalAlignmentyour buttons are not set to UIControlHorizontalAlignmentFilland UIControlVerticalAlignmentFillaccordingly. These values ​​scale the button image to fill the button frame. Any other value aligns the image accordingly.

+19
source

Use image framing to accommodate the non-resizable image elements found in the message on the stack, 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];
+4
source

All Articles