Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom UIButton image iOS

Is it possible to have a custom UIButton that has an image covering only half of it? I imagine it would 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 which only has a 50x50px image on the top half, and to be transparent on the bottom half.

I know how to create a custom button and everything. Im just woondering what the property is that controls the stretching of the backgroundImage.

Thanks!

like image 666
bkbeachlabs Avatar asked Jul 08 '12 06:07

bkbeachlabs


1 Answers

Use

[someButton setImage:[UIImage imageNamed:@"buttonPicture"] forState: UIControlStateNormal];
 someButton.imageEdgeInsets = UIEdgeInsetsMake(-50, 0, 0, 0);
like image 95
Inder Kumar Rathore Avatar answered Sep 28 '22 09:09

Inder Kumar Rathore