美文网首页
view圆角

view圆角

作者: 44b6889cedeb | 来源:发表于2023-09-19 16:32 被阅读0次

.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

相关文章

网友评论

      本文标题:view圆角

      本文链接:https://www.haomeiwen.com/subject/odxwvdtx.html