通过Layer层设置圆形头像
创建一个正方形的UIImageView对象命名为thumbnail。为了保证能够产生一个圆形图片这里必须是正方形。
[thumbnail.layer setCornerRadius:CGRectGetHeight(thumbnail.bounds) /2];//设置圆形半径
thumbnail.layer.masksToBounds = YES;
thumbnail.layer.borderWidth = 3;//设置外环宽度
thumbnail.layer.borderColor = [[UIColor greenColor] CGColor];//设置外环颜色
thumbnail.layer.contents = (id)tempImage.CGImage;//设置图片
通过如上代码就能实现一个圆形头像了。