zoukankan      html  css  js  c++  java
  • Button倒角,单边角,多边角

     最近有个ui的同事抱怨说她公司的前段开发动不动就让她切个小图,理由是实现不了,像下面这种小功能:

    其实这也是按钮的倒圆角,并不难。上代码:

    .h

    #import <UIKit/UIKit.h>

     

    @interface YMBtnCorner : UIButton

     

    //左上角

    - (void)ym_rectCorner:(CGFloat)radius conrners:(UIRectCorner)corners;

     

    @end

    .m

    #import "YMBtnCorner.h"

     

    @implementation YMBtnCorner

     

    - (void)ym_rectCorner:(CGFloat)radius conrners:(UIRectCorner)corners

    {

        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(radius, radius)];

        

        CAShapeLayer *maskLayer = [CAShapeLayer layer];

        maskLayer.frame = self.bounds;

        maskLayer.path = maskPath.CGPath;

        

        self.layer.mask = maskLayer;

    }

     

    @end

    用法:

        //左上

        [self.topLeftCorner ym_rectCorner:10.0 conrners:UIRectCornerTopLeft];

        //左下

        [self.bottomLeftcorner ym_rectCorner:10 conrners:UIRectCornerBottomLeft];

        //右上

        [self.topRightCorner ym_rectCorner:10 conrners:UIRectCornerTopRight];

        //右下

        [self.bottomRightCorner ym_rectCorner:10 conrners:UIRectCornerBottomRight];

        //四个角

        [self.allCorner ym_rectCorner:10 conrners:UIRectCornerAllCorners];

        //左右上角

        [self.topLeftRightCorner ym_rectCorner:10 conrners:UIRectCornerTopRight | UIRectCornerTopLeft];

        //左右下角

        [self.bottomLeftRightCorner ym_rectCorner:10 conrners:UIRectCornerBottomRight | UIRectCornerBottomLeft];

        //左上右下

        [self.topLeftBottomRight ym_rectCorner:10 conrners:UIRectCornerTopLeft | UIRectCornerBottomRight];

        //左下右上

        [self.bottomLeftTopRight ym_rectCorner:10 conrners:UIRectCornerBottomLeft | UIRectCornerTopRight];

        //左边

        [self.leftCorner ym_rectCorner:10 conrners:UIRectCornerBottomLeft | UIRectCornerTopLeft];

        //右边

        [self.rightCorner ym_rectCorner:10 conrners:UIRectCornerBottomRight | UIRectCornerTopRight];

  • 相关阅读:
    一个apache安装后无法启动的原因分析
    数字的一点考虑
    [转]bat方式上删除注册表键,项
    题解 P2016 【战略游戏】
    题解 P1403 【[AHOI2005]约数研究】
    题解 P1317 【低洼地】
    2020面向对象程序设计寒假作业3 设计思想
    题解 P1829 【[国家集训队]Crash的数字表格 / JZPTAB】
    题解 P1082 【同余方程】
    Unity3D读取外部Text
  • 原文地址:https://www.cnblogs.com/ljj-Andrew-519/p/9118045.html
Copyright © 2011-2022 走看看