.h文件中
@interface UIView (EX)
- (void)addCorner:(CGFloat)corner byRounding:(UIRectCorner)corners;
@end
.m文件中
#import "UIView+EX.h"
@implementation UIView (EX)
- (void)addCorner:(CGFloat)corner byRounding:(UIRectCorner)rounding
{
[self layoutIfNeeded];
//add mask
CGFloatcornerRadius = corner;
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.path = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:rounding cornerRadii:CGSizeMake(cornerRadius, cornerRadius)].CGPath;
self.layer.mask= maskLayer;
}
@end