zoukankan      html  css  js  c++  java
  • 使用category给UIButton设置一个较大的点击区

    使用category,来给UIButton设置一个较大的点击区

    @interface ExtendedHitButton: UIButton
    
    + (instancetype) extendedHitButton;
    
    - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event;
    
    @end
    
    @implementation ExtendedHitButton
    
    + (instancetype) extendedHitButton {
        return (ExtendedHitButton *) [ExtendedHitButton buttonWithType:UIButtonTypeCustom];
    }
    
    - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
        CGRect relativeFrame = self.bounds;
        UIEdgeInsets hitTestEdgeInsets = UIEdgeInsetsMake(-44, -44, -44, -44);
        CGRect hitFrame = UIEdgeInsetsInsetRect(relativeFrame, hitTestEdgeInsets);
        return CGRectContainsPoint(hitFrame, point);
    }
    
    @end

    链接:http://stackoverflow.com/questions/808503/uibutton-making-the-hit-area-larger-than-the-default-hit-area

  • 相关阅读:
    洛谷 P1313 计算系数
    洛谷 P1088 火星人
    洛谷 P1049 装箱问题
    P5016 龙虎斗
    洛谷P1208
    求lca
    没有上司的舞会
    最短路spfa
    懒羊羊找朋友
    简单的图论问题之单源最短路dijkstra算法
  • 原文地址:https://www.cnblogs.com/samniu/p/3655533.html
Copyright © 2011-2022 走看看