是否可以在不改变按钮背景图像大小的情况下增加按钮的可点击区域
I tried:
[shareButton setContentEdgeInsets:UIEdgeInsetsMake(top, left, bottom, right)];
&
[shareButton setImageEdgeInsets:UIEdgeInsetsMake(top, left, bottom, right)];
但这些都不起作用。
有什么建议吗?
使 UIButton 类型为buttonWithType:UIButtonTypeCustom
并为其指定较小尺寸的图像。
不要将图像设置为背景图像,否则它会随着按钮一起变大。将其设置为主图像。
例如,如果您想要将可点击区域设置为 64x64 大小,并且想要显示大小为 32x32 的图像:按钮大小应为 64x64,图像大小应为 32x32。
以编程方式:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
// use an image with the desired size (for example 32x32)
[button setImage: [UIImage imageNamed: @"buttonIcon.png"] forState: UIControlStateNormal];
// just set the frame of the button (64x64)
[button setFrame: CGRectMake(xPositionOfMyButton, yPositionOfMyButton, 64, 64)];
界面生成器:
![Interface Builder example](https://i.stack.imgur.com/2YOYJ.png)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)