美文网首页
设置图片视图的圆角真正不卡顿,高效率方式

设置图片视图的圆角真正不卡顿,高效率方式

作者: lixiangdev | 来源:发表于2016-08-17 16:12 被阅读0次
/*以前的方式*/
self.iconImage.layer.cornerRadius = 20; 
self.iconImage.layer.masksToBounds = YES;

/*现在的方式*/
- (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;
}

相关文章

网友评论

      本文标题:设置图片视图的圆角真正不卡顿,高效率方式

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