1.使用layer去裁剪 這兩行代碼在iOS9之前滾動tableview的時候會出現(xiàn)卡頓的顯現(xiàn),iOS9已經(jīng)修復(fù)了卡頓現(xiàn)象,建議使用第二種方法
UIImage *image = [UIImage imageNamed:@"avar"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.layer.cornerRadius = image.size.width/2;
imageView.layer.masksToBounds = YES;```
2.使用上下文裁剪圖片
<pre> UIGraphicsBeginImageContextWithOptions(image.size, NO, 0);
//描述裁剪區(qū)域
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
//設(shè)置裁剪區(qū)域
[path addClip];
//畫圖片
[image drawAtPoint:CGPointZero];
//取出圖片
image = UIGraphicsGetImageFromCurrentImageContext();
//關(guān)閉上下文
UIGraphicsEndImageContext();
imageView.image = image;</pre>