如何高性能的給UIImageView加個圓角?(不准說layer.cornerRadius!)


豆電雨 搬磚自味精: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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM