UIImage添加生成圆角图片

开发中遇到问题搜索的结果,来自他人,不做其他用途,未能注明来源,如有侵权联系本人删除。

给UIImage添加生成圆角图片的扩展API:这是on-screen-rendering

- (UIImage *)imageWithCornerRadius:(CGFloat)radius {

CGRect rect = (CGRect){0.f, 0.f, self.size};

UIGraphicsBeginImageContextWithOptions(self.size,NO,UIScreen.mainScreen.scale);

CGContextAddPath(UIGraphicsGetCurrentContext(), [UIBezierPathbezierPathWithRoundedRect:rect cornerRadius:radius].CGPath);

CGContextClip(UIGraphicsGetCurrentContext());

[selfdrawInRect:rect];

UIImage*image =UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

returnimage;

你可能感兴趣的:(UIImage添加生成圆角图片)