记录一下,这两天要用到的知识点。
效果图:
- (UIImage *) ellipseImage: (UIImage *) image withInset: (CGFloat) inset;
- (UIImage *) ellipseImage: (UIImage *) image withInset: (CGFloat) inset withBorderWidth:(CGFloat)width withBorderColor:(UIColor*)color;
//不要边框,只把图片变成圆形
- (UIImage *) ellipseImage: (UIImage *) image withInset: (CGFloat) inset
{
return [self ellipseImage:image withInset:inset withBorderWidth:0 withBorderColor:[UIColor clearColor]];
}
- (UIImage *) ellipseImage: (UIImage *) image withInset: (CGFloat) inset withBorderWidth:(CGFloat)width withBorderColor:(UIColor*)color
{
UIGraphicsBeginImageContext(image.size);
CGContextRef context = UIGraphicsGetCurrentContext();
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];
if (width > 0) {
CGContextSetStrokeColorWithColor(context, color.CGColor);
CGContextSetLineCap(context,kCGLineCapButt);
CGContextSetLineWidth(context, width);
CGContextAddEllipseInRect(context, CGRectMake(inset + width/2, inset + width/2, image.size.width - width- inset * 2.0f, image.size.height - width - inset * 2.0f));//在这个框中画圆
CGContextStrokePath(context);
}
UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newimg;
}
http://blog.csdn.net/x32sky/article/details/8283433
这里还有3种 思路,不知道哪个的效果最符合要求。