IOS方形头像如何变成圆形

方法一:直接使用UIView对应图层的cornerRadius

        self.layer.cornerRadius     = CGRectGetWidth(self.bounds)/2.f;

        self.clipsToBounds          = YES;

方法二:使用图层遮罩

    CAShapeLayer* mask = [CAShapeLayer layer];

        CGFloat width = self.frame.size.width;

        UIBezierPath* path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(width/2,width/2)  radius:width /2 startAngle:0 endAngle:2*M_PI clockwise:YES];

        mask.path = path.CGPath;

        self.layer.mask = mask;

posted @ 2015-05-17 16:34  郭晓倩  阅读(525)  评论(0编辑  收藏  举报