自建一个分类可以设置。
-(void)cornerImageWithSize:(CGSize)size fillColor:(UIColor *)fillColor completion:(void(^)(UIImage *resultImage))completion;
-(void)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();
dispatch_async(dispatch_get_main_queue(), ^{
if (completion != nil) {
completion(result);
}
});
});
}