自定义UIButton图像iOS

bkb*_*abs 5 iphone image button ipad ios

是否可以拥有一个自定义UIButton,其图像只覆盖其中的一半?我想它会是这样的:

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?? */

.
.
.
Run Code Online (Sandbox Code Playgroud)

我希望有一个50x100px按钮,上半部分只有50x50px图像,下半部分透明.

我知道如何创建自定义按钮和一切.我只是想知道什么属性控制backgroundImage的拉伸.

谢谢!

Ind*_*ore 7

使用

[someButton setImage:[UIImage imageNamed:@"buttonPicture"] forState: UIControlStateNormal];
 someButton.imageEdgeInsets = UIEdgeInsetsMake(-50, 0, 0, 0);
Run Code Online (Sandbox Code Playgroud)