Quartz2D指定显示范围

时间:2023-03-09 16:59:34
Quartz2D指定显示范围

在qq中,可以看到头像是圆形显示的,通过CGContextClip可以设置

CGContextRef context=UIGraphicsGetCurrentContext();
     CGContextAddEllipseInRect(context, CGRectMake(100, 100, 100, 100));
     CGContextClip(context);
     UIImage *img=[UIImage imageNamed:@"img.jpg"];
    [img drawAtPoint:CGPointMake(100, 100)];

Quartz2D指定显示范围

 CGContextRef context=UIGraphicsGetCurrentContext();
     UIImage *img=[UIImage imageNamed:@"img.jpg"];
     CGContextMoveToPoint(context, 30, 120);
     CGContextAddLineToPoint(context, 50, 200);
     CGContextAddLineToPoint(context, 200, 60);
     CGContextClosePath(context);
     CGContextClip(context);
    [img drawAtPoint:CGPointMake(30, 120)];

Quartz2D指定显示范围