OC裁剪圆形图片加边框

18-11-26 00:49 字数 715 阅读 2062 已编辑

alt text

// 加载图片
UIImage *img = [UIImage imageNamed:@"165a2965fb1d8727"];
// 边框宽度
CGFloat borderW = 10;
// 确定边框宽度
CGSize size = CGSizeMake(img.size.width + 2 * borderW, img.size.height + 2 * borderW);
// 开启上下文
UIGraphicsBeginImageContextWithOptions(size, NO, 0);
// 绘制大图,显示出来
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, size.width, size.height)];
[[UIColor blueColor] setFill];
[path fill];
// 绘制小圆,设置裁剪区域
UIBezierPath *clipPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(borderW, borderW, img.size.width, img.size.height)];
[clipPath addClip];
// 把图片绘制到上下文中
[img drawAtPoint:CGPointMake(borderW, borderW)];
// 从上下文中获取图片
UIImage *newImg = UIGraphicsGetImageFromCurrentImageContext();
// 关闭上下文
UIGraphicsEndImageContext();

// 显示到页面中
self.imgView.image = newImg;
1人点赞>
关注 收藏 改进 举报
0 条评论
排序方式 时间 投票
快来抢占一楼吧
请登录后发表评论
站长 @ 十七度
文章
380
粉丝
23
喜欢
191
收藏
31
排名 : 1
访问 : 128.34万
私信