美文网首页
iOS开发 -- 指定位置设置圆角

iOS开发 -- 指定位置设置圆角

作者: 空空_Jiminy | 来源:发表于2020-06-21 22:46 被阅读0次

    使用CAShaperLayer和UIBezier可解。
    corners参数可选:corners:UIRectCornerTopRight | UIRectCornerTopLeft | UIRectCornerBottomLeft | UIRectCornerBottomRight

    @implementation UIView (Extension)
    ///设置圆角 corners:UIRectCornerTopRight | UIRectCornerTopLeft | UIRectCornerBottomLeft | UIRectCornerBottomRight
    
    - (void)bezierCornerRadius:(CGFloat)radius rectCorners:(UIRectCorner)corners {
        self.layer.masksToBounds = YES;
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(radius, radius)];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = self.bounds;
        maskLayer.path = maskPath.CGPath;
        self.layer.mask = maskLayer;
    }
    
    @end
    

    相关文章

      网友评论

          本文标题:iOS开发 -- 指定位置设置圆角

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