• 增加按钮点击范围


    有时候按钮比较小, 不容易点击, 下面说一种扩大按钮点击范围. 方法有很多,这里只说一种

    #import <UIKit/UIKit.h>
    
    @interface UIButton (TouchAreaInset)
    /**
     *  @brief  设置按钮额外热区
     */
    @property (nonatomic, assign) UIEdgeInsets touchAreaInsets;
    
    @end
    #import <objc/runtime.h>
    #import "UIButton+TouchAreaInsets.h"
    
    @implementation UIButton (TouchAreaInsets)
    
    - (UIEdgeInsets)touchAreaInsets
    {
        return [objc_getAssociatedObject(self, @selector(touchAreaInsets)) UIEdgeInsetsValue];
    }
    /**
     *  @brief  设置按钮额外热区
     */
    - (void)setTouchAreaInsets:(UIEdgeInsets)touchAreaInsets
    {
        NSValue *value = [NSValue valueWithUIEdgeInsets:touchAreaInsets];
        objc_setAssociatedObject(self, @selector(touchAreaInsets), value, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    }
    
    - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
    {
        UIEdgeInsets touchAreaInsets = self.touchAreaInsets;
        CGRect bounds = self.bounds;
        bounds = CGRectMake(bounds.origin.x - touchAreaInsets.left,
                            bounds.origin.y - touchAreaInsets.top,
                            bounds.size.width + touchAreaInsets.left + touchAreaInsets.right,
                            bounds.size.height + touchAreaInsets.top + touchAreaInsets.bottom);
        return CGRectContainsPoint(bounds, point);
    }
    
    @end

    Demo不上了.

  • 相关阅读:
    RDS 工作笔记
    网站测试需要提供的参数和结果分析
    php 安全编程
    留住青春的格子
    保持工作精力旺盛的方法
    百万格子的标签认领可以提高你在alexa的排名的格子
    老电影,似水流年的记忆
    五行 八字 计算
    iis6.0 的 性能比较
    各种情绪和调节方法
  • 原文地址:https://www.cnblogs.com/dianming/p/6929574.html
Copyright © 2020-2023  润新知