繁体   English   中英

自定义UIButton图像iOS

[英]Custom UIButton image 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?? */

.
.
.

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

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

谢谢!

使用

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

我想你可以:

  1. 将您的按钮图像创建为50x100px图像(与按钮大小相同);

  2. 使这个图像是半透明的(PNG与alpha),

而不是试图给按钮分配一个只覆盖其中一半的较小图像,并防止拉伸。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM