将图片转换成圆形,适用于头像等。
UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
imageView.image = image;
CGPoint center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
CGFloat radius = MIN(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center
radius:radius
startAngle:0
endAngle:2*M_PI
clockwise:YES];
CAShapeLayer *shape = [CAShapeLayer layer];
shape.path = path.CGPath;
imageView.layer.mask = shape;
[self addSubview:imageView];