如何增加UIButton的选择范围? [英] How to increase selection area of UIButton?

查看:94
本文介绍了如何增加UIButton的选择范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have made the UIButton programmatically

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];

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

It is looked as the right button in above image. Now the requirement is that the selection area of this button should be more than then the uibutton image. So that the user will be able to click the button easily by touching on near by area of particular button.

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

我试图设置图片插入但是它使图像不规则。请查看此问题。

I tried to set the image inset but it making the image irregular. Please look upon this issue.

推荐答案

您可以通过设置按钮的 contentEdgeInsets ,例如:

You can achieve this by setting the button's contentEdgeInsets, for example:

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

这篇关于如何增加UIButton的选择范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆