写一个UIView扩展
1. .h文件
@interface UIView (Corner) - (void)setCornerWithType:(UIRectCorner)type Radius:(CGFloat)radius; @end
2. .m文件
#import "UIView+Corner.h" @implementation UIView (Corner) - (void)setCornerWithType:(UIRectCorner)type Radius:(CGFloat)radius { UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:type cornerRadii:CGSizeMake(radius,radius)]; CAShapeLayer *layer = [[CAShapeLayer alloc] init]; layer.frame = self.bounds; layer.path = path.CGPath; self.layer.mask = layer; } @end