view圆角

2023-09-19  本文已影响0人  44b6889cedeb

.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

上一篇 下一篇

猜你喜欢

热点阅读