iOS 图形异步绘制圆角

iOS 图形异步绘制圆角

- (void)WZX_cornerImageWithSize:(CGSize)size fillColor:(UIColor *)fillColor completion:(void (^)(UIImage *))completion{

   dispatch_async(dispatch_get_global_queue(0, 0), ^{
      
       // 1.利用绘图
       UIGraphicsBeginImageContextWithOptions(size, YES, 0);
       
       CGRect rect = CGRectMake(0, 0, size.width, size.height);
       
       // 2.设置填充颜色
       [fillColor setFill];
       UIRectFill(rect);
       
       // 3. 利用 贝塞尔路径 ‘裁切’ 效果
       UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:rect];
       
       [path addClip];
       
       // 4.绘制图像
       [self drawInRect:rect];
       
       // 5.取得结果
       UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
       
       // 6. 关闭上下文
       UIGraphicsEndImageContext();
       
       // 7. 完成回调
       dispatch_async(dispatch_get_main_queue(), ^{
           if(completion != nil){
               completion(result);
           }
           
       });

   });

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

推荐阅读更多精彩内容