美文网首页
IOS 给任何一个VIew添加圆角

IOS 给任何一个VIew添加圆角

作者: 梦想不是遥不可及的 | 来源:发表于2017-10-26 13:09 被阅读0次

/**

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 = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:Left|Right|BottomLeft|BottomRight cornerRadii:size];

CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];

maskLayer.frame = view.bounds;

maskLayer.path = maskPath.CGPath;

view.layer.mask = maskLayer;

}

相关文章

网友评论

      本文标题:IOS 给任何一个VIew添加圆角

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