标签:
加载需要显示的图片
UIImage *image = [UIImage imageNamed:@"资源中图片的名字"];
初始化用到的变量
//图片的宽宽高
CGFloat imageWH = image.size.width;
//边界的宽度
CGFloat border = 1;
//背景区域的宽高
CGFloat ovalWH = imageWH + 2 * border;
开启图形上下文(尺寸为背景区域的尺寸
)
//设置图形上下文的尺寸
CGSize size = CGSizeMake(ovalWH, ovalWH);
//开启图形上下文
UIGraphicsBeginImageContextWithOptions(size, NO, 0);
绘制背景区域
//绘制封闭的圆形路径
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, ovalWH, ovalWH)];
//设置填充颜色
[[UIColor blueColor] set];
//渲染所绘制的区域
[path fill];
绘制图片区域
//绘制封闭的圆形区域
UIBezierPath *clipPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(border, border, imageWH, imageWH)];
//设置超出区域的内容剪掉(不显示)
[clipPath addClip];
//见图片绘制到圆形区域内,从点(border, border)开始
[image drawAtPoint:CGPointMake(border, border)];
从图形上下文中取出绘制的图片
UIImage *clipImage = UIGraphicsGetImageFromCurrentImageContext();
将图片显示到imageView上
self.imageView.image = clipImage;
关闭图形上下文
UIGraphicsEndImageContext();
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/qq_26583311/article/details/47211483