iOS view的任意一个或多个角变圆角

来源:互联网 发布:数据库采集技术 编辑:程序博客网 时间:2024/06/06 00:05

/**

 view 传入要变圆角的视图

 size自己根据需要设置角度大小

 后面的4个角 BOOL 1 是设置该角为圆角 0 不改变 

*/

- (void)renYiYuanJiao:(UIView *)view size:(CGSize)size left:(BOOL)left right:(BOOL)right bottomLeft:(BOOL)bottomLeft bottomRight:(BOOL)bottomRight {

    UIRectCorner Left =0;

    UIRectCorner Right =0;

    UIRectCorner BottomLeft =0;

    UIRectCorner BottomRight =0;

    if (left) {

       Left =UIRectCornerTopLeft;

    }

    if (right) {

        Right =UIRectCornerTopRight;;

    }

    if (bottomLeft) {

        BottomLeft = UIRectCornerBottomLeft;

    }

    if (bottomRight) {

        BottomRight = UIRectCornerBottomRight;

    }

    UIBezierPath *maskPath = [UIBezierPathbezierPathWithRoundedRect:view.boundsbyRoundingCorners:Left|Right|BottomLeft|BottomRightcornerRadii:size];

    CAShapeLayer *maskLayer = [[CAShapeLayeralloc] init];

    maskLayer.frame = view.bounds;

    maskLayer.path = maskPath.CGPath;

    view.layer.mask = maskLayer;

}

0 0