您的位置:首页 > 产品设计 > UI/UE

如何高性能的给UIImageView加个圆角?(不准说layer.cornerRadius!)

2020-01-15 11:51 1611 查看

豆电雨 搬砖自味精:http://awhisper.github.io/2016/03/12/滚动圆角卡顿刨根问底/

 使用Quartz2D直接绘制图片

步骤: 
  a、创建目标大小(cropWidth,cropHeight)的画布。

  b、使用UIImage的drawInRect方法进行绘制的时候,指定rect为(-x,-y,width,height)。

  c、从画布中得到裁剪后的图像。

 

- (UIImage*)cropImageWithRect:(CGRect)cropRect
{
  //豆电雨 CGRect drawRect = CGRectMake(-cropRect.origin.x , -cropRect.origin.y, self.size.width * self.scale, self.size.height * self.scale); UIGraphicsBeginImageContext(cropRect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextClearRect(context, CGRectMake(0, 0, cropRect.size.width, cropRect.size.height)); [self drawInRect:drawRect]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; } @end

 

转载于:https://www.cnblogs.com/starainDou/p/5289408.html

  • 点赞
  • 收藏
  • 分享
  • 文章举报
ad4576690 发布了1 篇原创文章 · 获赞 1 · 访问量 1431 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: