CAShapeLayer把图片做成圆形效果

      利用CAShapeLayer可以制作出任意的几何图形,把它作为UIImageView的遮罩,达到把图片做成圆形效果。

        //创建个人主页头部的用户头像

        self.userHead = [[UIImageView alloc]initWithFrame:CGRectMake(10, 35, 80, 80)];
        self.userHead.image = [UIImage imageNamed:@"start.jpg"];
        
        //创建圆形遮罩,把用户头像变成圆形
        UIBezierPath* path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(40, 40) radius:40 startAngle:0 endAngle:2*M_PI clockwise:YES];
        CAShapeLayer* shape = [CAShapeLayer layer];
        shape.path = path.CGPath;
        self.userHead.layer.mask = shape;

        [self addSubview:self.userHead];


CAShapeLayer把图片做成圆形效果_第1张图片

你可能感兴趣的:(CAShapeLayer把图片做成圆形效果)