切圆角

作者: 只是个少年 | 来源:发表于2019-01-23 18:56 被阅读0次
    四个不同的圆角
            _menuView = [[UIView alloc] initWithFrame:CGRectMake(12, menuViewY, KScreenWidth -24, 51)];
            _menuView.backgroundColor = [UIColor cyanColor];
            CGSize size = _menuView.size;
            CGFloat imgW = size.width;
            CGFloat imgH = size.height;
            CGFloat downLeft = 5;
            CGFloat upLeft = 10;
            UIBezierPath *path = [UIBezierPath bezierPath];
            //左下
            [path addArcWithCenter:CGPointMake(downLeft, imgH - downLeft) radius:downLeft startAngle:M_PI_2 endAngle:M_PI clockwise:YES];
            //左上
            [path addArcWithCenter:CGPointMake(upLeft, upLeft) radius:upLeft startAngle:M_PI endAngle:M_PI_2 * 3 clockwise:YES];
            //右上
            [path addArcWithCenter:CGPointMake(imgW - upLeft, upLeft) radius:upLeft startAngle:M_PI_2 * 3 endAngle:0 clockwise:YES];
            //右下
            [path addArcWithCenter:CGPointMake(imgW - downLeft, imgH - downLeft) radius:downLeft startAngle:0 endAngle:M_PI_2 clockwise:YES];
            [path closePath];
    
            CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
            maskLayer.frame = _menuView.bounds;
            maskLayer.path = path.CGPath;
            _menuView.layer.mask = maskLayer;
    
    不同方位的圆角
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
                                                       byRoundingCorners:corner
                                                             cornerRadii:CGSizeMake(cornerRadii,
                                                                                    cornerRadii)];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = self.bounds;
        maskLayer.path = maskPath.CGPath;
        self.layer.mask = maskLayer;
    

    原文地址
    git地址

    相关文章

      网友评论

          本文标题:切圆角

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