1.xib设置图片圆角
Paste_Image.png
2.纯代码设置圆角(也可以由xib拉线添加),效率不高
- (void)drawRect:(CGRect)rect
{
[superdrawRect:rect];
self.imgView.layer.cornerRadius = 20;
self.imgView.clipsToBounds =YES;
}
3.设置图像圆角(高效率,不会造成卡顿,建议放到分类中使用)
/** 设置圆形图片(放到分类中使用) */
- (UIImage *)cutCircleImage {
UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0);
// 获取上下文
CGContextRef ctr = UIGraphicsGetCurrentContext();
// 设置圆形
CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
CGContextAddEllipseInRect(ctr, rect);
// 裁剪
CGContextClip(ctr);
// 将图片画上去
[self drawInRect:rect];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}