美文网首页
使用mask实现圆角

使用mask实现圆角

作者: Desert_Eagle | 来源:发表于2017-09-15 16:37 被阅读0次
- (void)viewDidLoad {
    [super viewDidLoad];

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
    imageView.image = [UIImage imageNamed:@"11"];
    
    [self.view addSubview:imageView];
    imageView.layer.mask = [self maskRadiusCorner:imageView];
}

- (CALayer *)maskRadiusCorner:(UIImageView *)imageView{
    // CAShapeLayer是CALayer的子类,通过UIBezierPath来绘制它的形状
    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    // 获取长宽
    maskLayer.frame = imageView.bounds;
    maskLayer.path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(imageView.bounds.size.width / 2, imageView.bounds.size.height / 2) radius:imageView.bounds.size.width / 2 startAngle:0 endAngle:2 * M_PI clockwise:YES].CGPath;
    return maskLayer;
}

相关文章

网友评论

      本文标题:使用mask实现圆角

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