设置圆形图片

设置圆形图片,有两种方式,具体如下:

1. 改变尺寸,在视觉上是圆形
_midImage.layer.cornerRadius = _midImage.width/2;
_midImage.layer.masksToBounds = YES;
2.绘制一个圆形图片
+ (UIImage*) circleImage:(UIImage*) image withParam:(CGFloat) inset {

    UIGraphicsBeginImageContext(image.size);

    CGContextRef context =UIGraphicsGetCurrentContext();

    CGContextSetLineWidth(context,inset);

    CGContextSetStrokeColorWithColor(context, [UIColor orangeColor].CGColor);

    CGRect rect = CGRectMake(inset, inset, image.size.width - inset * 2.0f, image.size.height - inset *2.0f);
    CGContextAddEllipseInRect(context, rect);

    CGContextClip(context);

    //在圆区域内画出image原图

    [image drawInRect:rect];

    CGContextAddEllipseInRect(context, rect);

    CGContextStrokePath(context);

    //生成新的image

    UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return newimg;
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容