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

 

相关文章:

猜你喜欢
  • 2021-10-28
  • 2022-12-23
  • 2021-04-23
  • 2022-12-23
  • 2021-11-28
相关资源
相似解决方案