是否可以在不改变按钮背景图片大小的情况下增加 UIButton 的可点击区域
is it possible to increase tapable area of UIButton without changing size of Button's background Image
我试过了:
[shareButton setContentEdgeInsets:UIEdgeInsetsMake(top, left, bottom, right)];
&
[shareButton setImageEdgeInsets:UIEdgeInsetsMake(top, left, bottom, right)];
但这些都不起作用.
有什么建议吗?
制作类型为 buttonWithType:UIButtonTypeCustom 的 UIButton 并为其分配一个较小尺寸的图像.
Make the UIButton of type buttonWithType:UIButtonTypeCustom and assign to it an image of a smaller size.
不要将图片设置为背景图片,否则它会随按钮一起增长.改为将其设置为主图像.
Do not set the image as the background image or it'll grow with the button. Set it as the main image instead.
例如,如果您想将可点击区域设置为 64x64 大小,并且想要显示大小为 32x32 的图像:按钮大小应为 64x64,图像大小应为 32x32.
For example if you want to set the tappable area to a 64x64 size and you want to show an image sized 32x32: the button size should be be 64x64 and the image size should be 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)];
界面构建器:
这篇关于如何在不增加背景图像大小的情况下增加(自定义类型)UIButton 的可点击(点击)区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何通过点击动画 UIImageview 以显示全屏?How to animate a UIImageview to display fullscreen by tapping on it?(如何通过点击动画 UIImageview 以显示全屏?)
停止 segue 并显示警报To stop segue and show alert(停止 segue 并显示警报)
iOS 5 故事板,以编程方式确定路径iOS 5 storyboard, programmatically determine path(iOS 5 故事板,以编程方式确定路径)
图标已经包含光泽效果Icon already includes gloss effects(图标已经包含光泽效果)
UIEdgeInsetsMake 是如何工作的?How does UIEdgeInsetsMake work?(UIEdgeInsetsMake 是如何工作的?)
UIProgressView 和自定义跟踪和进度图像(iOS 5 属性UIProgressView and Custom Track and Progress Images (iOS 5 properties)(UIProgressView 和自定义跟踪和进度图像(iOS 5 属性))