- (UIImage *)obtainCircleImage {
UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0);
// 获取上下文
CGContextRef ref = UIGraphicsGetCurrentContext();
// 设置圆形
CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
CGContextAddEllipseInRect(ref, rect);
// 裁剪
CGContextClip(ref);
// 将图片画上去
[self drawInRect:rect];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
ios代码设置圆角
最新推荐文章于 2023-08-04 09:48:04 发布
本文介绍了一个Objective-C方法,用于将任意UIImage转换为圆形图片。通过使用UIGraphics和Core Graphics框架,该方法首先创建一个与目标大小匹配的图像上下文,然后在该上下文中绘制一个与上下文相同尺寸的圆形路径,并将其作为裁剪区域。接着,原始图片被绘制到这个圆形区域内,最终从当前图像上下文中获取到圆形图片。

1374

被折叠的 条评论
为什么被折叠?



