导入#import <CoreGraphics/CoreGraphics.h>
CGFloat radius = 20;
UIRectCorner corner = UIRectCornerTopRight|UIRectCornerTopLeft; // 右上右左举例
if (@available(iOS 11.0,*)) { // iOS11以上苹果提供了属性
cornerRadiusView.layer.cornerRadius = radius;
cornerRadiusView.layer.maskedCorners = (CACornerMask)corner;
}else{ // iOS11已下用UIBezierPath设置
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:cornerRadiusView.bounds byRoundingCorners:corner cornerRadii:CGSizeMake(radius, radius)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
maskLayer.frame = cornerRadiusView.bounds;
maskLayer.path = path.CGPath;
cornerRadiusView.layer.mask = maskLayer;
}
网友评论