IOS 贝塞尔曲线切割圆角

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

 

posted @ 2018-11-15 17:00  宁静暖风  阅读(1529)  评论(0编辑  收藏  举报