首页 > 技术文章 > IOS 贝塞尔曲线切割圆角

dujiahong 2018-11-15 17:00 原文

写一个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

 

推荐阅读