How to increase selection area of UIButton?(如何增加 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)];
我尝试设置 image inset,但它使 image 不规则.请关注这个问题.
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 的选择区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何增加 UIButton 的选择区域?
基础教程推荐
- 在 iOS8 中无法获得正确的键盘高度值 2022-01-01
- 如何将多个组件添加到 PickerView? 2022-01-01
- - (CGRect)convertRect:(CGRect)rect toView:(UIView *)view 如何工作 2022-01-01
- 我的 UIImageView 的任务 2022-01-01
- 突出显示朗读文本(在 iPhone 的故事书类型应用程序中) 2022-01-01
- 新的@SystemApi 注解是什么意思,和@hide 有什么区别 2022-01-01
- 可可/目标C(OSX不是iOS)从子对象访问父对象 2022-01-01
- 在 appComponent dagger 2 中动态添加测试模块? 2022-01-01
- 在 Android 模拟器中激活网络位置提供程序? 2022-01-01
- Android:STATE_SELECTED不工作 2022-01-01
