美文网首页
iOS图片设置圆角的方法,此方法不会造成卡顿的现象

iOS图片设置圆角的方法,此方法不会造成卡顿的现象

作者: i得深刻方得S | 来源:发表于2016-08-11 09:08 被阅读48次

//  Copyright © 2016年 guoyasong. All rights reserved.

//此方法要放到分类中使用

#import "UIImage+SGimage.h"

@implementation UIImage (SGimage)

/** 设置圆形图片(放到分类中使用) */

- (UIImage *)cutCircleImage {

UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0);

// 获取上下文

CGContextRef ctr = UIGraphicsGetCurrentContext();

// 设置圆形

CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);

CGContextAddEllipseInRect(ctr, rect);

// 裁剪

CGContextClip(ctr);

// 将图片画上去

[self drawInRect:rect];

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return image;

}

@end

相关文章

网友评论

      本文标题:iOS图片设置圆角的方法,此方法不会造成卡顿的现象

      本文链接:https://www.haomeiwen.com/subject/ltojsttx.html