以下可讲视图裁剪成一个圆形或椭圆:
- (void) drawRect: (CGRect) aRect
{
UIImage *logo = [UIImageimageNamed:@"logo1.png"];
CGRect bounds = CGRectMake(0.0f, 0.0f,rect.origin.x + aRect.size.width, rect.origin.y + aRect.size.height);
// Create a new path
CGContextRef context = UIGraphicsGetCurrentContext();
CGMutablePathRef path = CGPathCreateMutable();
// Add circle to path
CGPathAddEllipseInRect(path, NULL, bounds);//这句话就是剪辑作用
CGContextAddPath(context, path);
// Clip to the circle and draw the logo
CGContextClip(context);
[logo drawInRect:bounds];
CFRelease(path);
}
使用Core Graphics绘制圆形裁剪图像
本文介绍如何使用Core Graphics API将一个矩形区域裁剪为圆形,并在此基础上绘制指定图片。通过创建路径并使用CGPathAddEllipseInRect方法添加椭圆形状,实现对图像的圆形裁剪。
2598

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



