開(kāi)發(fā)中遇到問(wèn)題搜索的結(jié)果竟纳,來(lái)自他人慨代,不做其他用途更哄,未能注明來(lái)源芋齿,如有侵權(quán)聯(lián)系本人刪除。
給UIImage添加生成圓角圖片的擴(kuò)展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;