切圆角

2019-01-23  本文已影响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地址

上一篇下一篇

猜你喜欢

热点阅读