给UIView指定角设置圆角

2019-10-17  本文已影响0人  RichieQ

通过UIRectCornerUIBezierPath组合给进行设置

// cornerRadius圆角大小,cornerRadius指定角
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(cornerRadius, cornerRadius)];
    maskLayer.maskLayer.frame = self.bounds;
    maskLayer.path = maskPath.CGPath;
    self.layer.mask = maskLayer;

Demo

上一篇 下一篇

猜你喜欢

热点阅读