UIImage 切圆

来源:互联网 发布:淘宝卖家延长发货时间 编辑:程序博客网 时间:2024/06/06 20:44

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

利用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];

0 0
原创粉丝点击