美文网首页
iOS  UIButton 优雅的扩大点击区域

iOS  UIButton 优雅的扩大点击区域

作者: 冰天无幻 | 来源:发表于2022-08-26 09:07 被阅读0次

通过重写pointInside方法

hitAreaPadding  是传入的size  可以定义为属性

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event

{

    if (self.hidden || self.alpha == 0 || self.userInteractionEnabled == NO || self.enabled == NO) {

       

        return NO;

    }

    CGRect bounds = self.bounds;

    bounds = CGRectInset(bounds, -self.hitAreaPadding.width, -self.hitAreaPadding.height);

    return CGRectContainsPoint(bounds, point);

}

来源:https://www.cnblogs.com/KingQiangzi/p/9883274.html

重写按钮的 hitTets 方法,判断 point 是否属于扩大范围内,属于就返回 self,让自己作为响应者

相关文章

网友评论

      本文标题:iOS  UIButton 优雅的扩大点击区域

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