ios - 如何增加UIButton的选择区域?

标签 ios objective-c uibutton

我已经以编程方式制作了UIButton

togglebutton = [UIButton buttonWithType:UIButtonTypeCustom];
togglebutton.frame = CGRectMake(42, 15, 80, 21);
[togglebutton addTarget:self action:@selector(toggleview)   
forControlEvents:UIControlEventTouchUpInside];
[togglebutton setImage:[UIImage imageNamed:@"squ.png"] forState:UIControlStateNormal];
[buttonView addSubview:togglebutton];

enter image description here

它看起来像上图中的右键。现在的要求是这个按钮的选择区域要大于uibutton图片。这样用户就可以通过触摸特定按钮附近的区域来轻松单击按钮。

[togglebutton setImageEdgeInsets: UIEdgeInsetsMake( 0, -30, 0, -25)];

我尝试设置image inset 但它使image 不规则。请关注这个问题。

最佳答案

可以通过设置按钮的contentEdgeInsets来实现,例如:

toggleButton.contentEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0); //set as you require 

关于ios - 如何增加UIButton的选择区域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17249104/

相关文章:

ios - TextView 第一次没有正确格式化文本,但第二次可以

ios - 要检查wifi是否开启但没有互联网连接

objective-c - Swift 函数的返回值

ios - 标题未显示在 UIButton 上

iphone - 按下时如何获取 UIButton 的标题

ios - 一个应用程序为不同的客户提供多种外观? (苹果规则)

ios - 访问另一个 View 的元素(iOS - 标签栏 Controller )

ios - 如何测试位标记的所有字段是否存在于另一个位掩码中?

iphone - UIButton 的响应时间

ios - ipad:为什么我的连续动画的第一个动画总是立即完成?