美文网首页
OC-按钮放大热区

OC-按钮放大热区

作者: 紫云夕月 | 来源:发表于2021-08-27 09:54 被阅读0次
    #import "UIButton+EnlargeTouchArea.h"
    
    @implementation UIButton (EnlargeTouchArea)
    - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent*)event
    {
        CGRect bounds = self.bounds;
        //若原热区小于44x44,则放大热区,否则保持原大小不变
        CGFloat widthDelta = MAX(44.0 - bounds.size.width, 0);
        CGFloat heightDelta = MAX(44.0 - bounds.size.height, 0);
        bounds = CGRectInset(bounds, -0.5 * widthDelta, -0.5 * heightDelta);
        return CGRectContainsPoint(bounds, point);
    }
    @end
    

    相关文章

      网友评论

          本文标题:OC-按钮放大热区

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