gpt4 book ai didi

ios - 如何在不增加背景图像大小的情况下增加(自定义类型)UIButton 的可点击(点击)区域

转载 作者:技术小花猫 更新时间:2023-10-29 10:45:09 24 4
gpt4 key购买 nike

是否可以在不改变按钮背景图像大小的情况下增加 UIButton 的可点击区域

我试过:

[shareButton setContentEdgeInsets:UIEdgeInsetsMake(top, left, bottom, right)];

&

[shareButton setImageEdgeInsets:UIEdgeInsetsMake(top, left, bottom, right)];

但这些都不起作用。

有什么建议吗?

最佳答案

创建 buttonWithType:UIButtonTypeCustom 类型的 UIButton 并为其分配一个较小尺寸的图像。

不要将图像设置为背景图像,否则它会随着按钮一起增长。将其设置为主图像。

例如,如果您要将可点击区域设置为 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

关于ios - 如何在不增加背景图像大小的情况下增加(自定义类型)UIButton 的可点击(点击)区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13246452/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com