IOS头像圆环效果
2016-10-14 本文已影响127人
NSLogGPX
- (void)drawRect:(CGRect)rect {
// 1.加载图片
UIImage *image = [UIImage imageNamed:@"456"];
// 2.开启图形上下文
CGSize size = CGSizeMake(image.size.width + 20 , image.size.height + 20);
UIGraphicsBeginImageContextWithOptions(size, NO, 0);
// 绘制大圆 圆环效果
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, size.width, size.height)];
[[UIColor grayColor] set];
[path fill];
// 裁剪区域
UIBezierPath *clipPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(10, 10, image.size.width, image.size.height)];
[clipPath addClip];
// 3.把图片绘制到上下文当中
[image drawAtPoint:CGPointMake(10, 10)];
// 4.从图形上下文中取出图片
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
// 5.关闭上下文
UIGraphicsEndPDFContext();
self.imageView.image = newImage;
}
效果图
Simulator Screen Shot 2016年10月14日 上午9.09.42.png