/**
- 生成圆角的图片
- @param originImage 原始图片
- @param borderColor 边框原色
- @param borderWidth 边框宽度
- @return 圆形图片
*/
-
(UIImage *)circleImage:(UIImage *)originImage borderColor:(UIColor *)borderColor borderWidth:(CGFloat)borderWidth
{
//设置边框宽度
CGFloat imageWH = originImage.size.width;//计算外圆的尺寸
CGFloat ovalWH = imageWH + 2 * borderWidth;//开启上下文
UIGraphicsBeginImageContextWithOptions(originImage.size, NO, 0);//画一个大的圆形
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, ovalWH, ovalWH)];[borderColor set];
[path fill];
//设置裁剪区域
UIBezierPath *clipPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(borderWidth, borderWidth, imageWH, imageWH)];
[clipPath addClip];//绘制图片
[originImage drawAtPoint:CGPointMake(borderWidth, borderWidth)];//从上下文中获取图片
UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();//关闭上下文
UIGraphicsEndImageContext();
return resultImage;
}