美文网首页
增加UIButton热区(响应范围)

增加UIButton热区(响应范围)

作者: _我和你一样 | 来源:发表于2021-06-22 17:00 被阅读0次

button太小,想增加其可点击区域?
要么就把按钮本身设置的大一些,要么增大其可以响应的区域。

采用继承的方式,重写UIView的下面方法,来更改UIbutton的响应范围,使button响应更大的区域或者更小的区域
- (BOOL)pointInside:(CGPoint)point withEvent:(nullable UIEvent *)event

@interface MyButton : UIButton

/// 触控区域左右两侧扩大或缩小的偏移量,左右相同,>0表示扩大点击区域,<0表示缩小点击区域
@property (nonatomic) CGFloat touchWidthOffset;

/// 触控区域上下两侧扩大或缩小的偏移量,上下相同,>0表示扩大点击区域,<0表示缩小点击区域
@property (nonatomic) CGFloat touchHeightOffset;

@end

@implementation MyButton

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
    CGRect bounds = self.bounds;
    bounds = CGRectInset(bounds, -self.touchWidthOffset, -self.touchHeightOffset);
    return CGRectContainsPoint(bounds, point);
}

@end

想要让按钮不显示高亮状态?

// 重写系统setHighlighted方法,取消按钮点击高亮显示
- (void)setHighlighted:(BOOL)highlighted {
}

相关文章

  • 增加UIButton热区(响应范围)

    button太小,想增加其可点击区域?要么就把按钮本身设置的大一些,要么增大其可以响应的区域。 采用继承的方式,重...

  • 响应链(II)

    扩大UIButton的响应区   通过重载UIButton的 -(BOOL) pointInside: with...

  • UIButton 点击响应范围扩展

    不多说直接上代码链接 https://github.com/HeYunDong/ExpandButton

  • UIButton 点击响应范围扩展

    不多说直接上代码链接 https://github.com/HeYunDong/ExpandButton #imp...

  • 增加UIButton的点击范围

    背景 在我们日常生活中,UIButton被用到各种各样的场景之中。为了展示出其小巧和美观往往都把它做的很小也就是给...

  • 增加UIButton的响应区域

    经常遇到UIButton对象"点了没反应"或"很难被点击到"的情况. 有时候是因为其frame的size设置...

  • UIButton 热区放大

    Apple 人机交互指南中指出,按钮点击热区应不小于44x44pt,否则这个按钮就会让用户觉得“很难用”。解决方法...

  • 一个好用的UIButton扩展

    改变UIButton的响应区域 UIButton+ExtendTouchRect.h UIButton+Exten...

  • UIButton

    1. 设置button.titleLabel的文字居左或居右显示: 2. 修改button热区(响应范围) 在UI...

  • Hit-test view扩大UIButton的响应热区

    相信大家都遇到小图button点击热区太小问题,各种计算不说,写出的代码还很难看不便于维护,如果我们用用hit-t...

网友评论

      本文标题:增加UIButton热区(响应范围)

      本文链接:https://www.haomeiwen.com/subject/qirmyltx.html