【发布时间】:2013-06-22 09:13:31
【问题描述】:
我以编程方式制作了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];
在上图中,它看起来像右边的按钮。现在的要求是这个按钮的选择区域应该大于uibutton图像。这样用户就可以通过触摸特定按钮附近的区域来轻松单击按钮。
[togglebutton setImageEdgeInsets: UIEdgeInsetsMake( 0, -30, 0, -25)];
我尝试设置image inset,但它却设置了image irregular。请关注这个问题。
【问题讨论】:
-
您是如何选择这些插图的?您还尝试了哪些其他值?
-
看看这个并尝试改变按钮图像的视图模式,然后它应该与插图一起工作并且图像应该保持不变 - developer.apple.com/library/ios/#documentation/WindowsViews/…
-
@Wain 我根据按钮和图像大小的差异设置图像插入
-
我推荐这个答案uibutton-making-the-hit-area-larger-than-the-default-hit-area。也许它可以帮助我们大多数人
标签: ios objective-c uibutton