方法1: 修改UIImageView的layer
imageView.layer.cornerRadius = self.size.width/2;
imageView.clipsToBounds = YES;
复制代码
方法2: 裁剪image
@implementation UIImage (SRExtension)
-(UIImage *)circleImage{
// NO:代表透明
UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0);
//获取图片上下文
CGContextRef ref = UIGraphicsGetCurrentContext();
//添加一个园
CGRect rect = CGRectMake(0, 0, self.size.width,self.size.height);
CGContextAddEllipseInRect(ref, rect);
//裁剪
CGContextClip(ref);
//画上去
[self drawInRect:rect];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
复制代码