zoukankan      html  css  js  c++  java
  • 增加按钮点击范围

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

    #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不上了.

  • 相关阅读:
    PLSQL游标
    SqlHelper助手
    机房重构前奏——三层转七层
    应用运筹管理经济
    C++——宏观把控
    操作系统——宏观把控
    .NET总结一
    深复制与浅复制
    设计模式之结构型
    设计模式之一对多
  • 原文地址:https://www.cnblogs.com/dianming/p/6929574.html
Copyright © 2011-2022 走看看