UIButton iOS Custom Image

Is it possible to have a custom UIButton with an image spanning only half? I assume it will be something like this:

UIButton *someButton = [UIButton buttonWithType:UIButtonTypeCustom];
[someButton setBackgroundImage:[UIImage imageNamed:@"buttonPicture"]];

/* Then there must be some property I can set that prevents the button from stretching the image?? */

.
.
.

I want to have a 50x100px button that has only a 50x50px image in the upper half and be transparent in the lower half.

I know how to create a custom button and that’s it. Im just shaking that property that controls the stretching of the backgroundImage.

Thank!

+5
source share
2 answers

Using

[someButton setImage:[UIImage imageNamed:@"buttonPicture"] forState: UIControlStateNormal];
 someButton.imageEdgeInsets = UIEdgeInsetsMake(-50, 0, 0, 0);
+7
source

I think you could:

  • create the image of your button as a 50x100px image (the same size as the button);

  • make this image translucent (PNG with alpha),

, , .

+1

All Articles