//通過繪圖的方式給圖片設(shè)置圓角证鸥,而view的‘layer.cornerRadius’方法是離屏渲染氯质,很消耗內(nèi)存髓涯,所以可以通過下面的方法給圖片設(shè)置圓角
//為imageView 添加類別杂数,給imageView的圖片設(shè)置圓角
-(void)imageWithCornerRadius:(CGFloat)radius
{
UIGraphicsBeginImageContextWithOptions(self.frame.size,NO,?UIScreen.mainScreen.scale);
CGContextAddPath(UIGraphicsGetCurrentContext(),?[UIBezierPathbezierPathWithRoundedRect:CGRectMake(0,?0,self.frame.size.width,self.frame.size.height)cornerRadius:radius].CGPath);
CGContextClip(UIGraphicsGetCurrentContext());
[self.imagedrawInRect:CGRectMake(0,?0,self.frame.size.width,self.frame.size.height)];
self.image?=?UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
//為UIImage添加生成圓角的API方法
-(UIImage*)imageWithCornerRadius:(CGFloat)radius
{
CGRect?rect?=?(CGRect){0.f,?0.f,self.size};
UIGraphicsBeginImageContextWithOptions(self.size,NO,?UIScreen.mainScreen.scale);
CGContextAddPath(UIGraphicsGetCurrentContext(),?[UIBezierPathbezierPathWithRoundedRect:rectcornerRadius:radius].CGPath);
CGContextClip(UIGraphicsGetCurrentContext());
[selfdrawInRect:rect];
UIImage*?image?=?UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
returnimage;
}