#pragma mark- convert a picture to a circle
-(uiimage*) Circleimage: (uiimage*) image withparam: (cgfloat) inset {
Uigraphicsbeginimagecontext(image.size);
Cgcontextref context = Uigraphicsgetcurrentcontext();
Cgcontextsetlinewidth(Context, 2);
Cgcontextsetstrokecolorwithcolor(context, [Uicolor Whitecolor]. Cgcolor);
cgrect rect = CGRectMake (inset, inset, image. Size. Width-inset * 2.0f, image. Size. Height-inset * 2.0f);
Cgcontextaddellipseinrect(context, rect);
Cgcontextclip (context);
[Image Drawinrect:rect];
Cgcontextaddellipseinrect(context, rect);
Cgcontextstrokepath(context);
UIImage *newimg = Uigraphicsgetimagefromcurrentimagecontext();
Uigraphicsendimagecontext();
return newimg;
}
The above code Note If you do not use cgcontextaddellipseinrect after cropping (context, rect);
Cgcontextstrokepath (context); This code will cause the background to be white when the task effect is not visible.
Here is the ellipse operation
iOS turns a picture into a circle