https://developer.apple.com/library/archive/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_paths/dq_paths.html#//apple_ref/doc/uid/TP30001066-CH211-TPXREF106
奇偶规则
- (void)drawRect:(CGRect)rect{
CGContextRef ref = UIGraphicsGetCurrentContext();
CGContextAddRect(ref, CGRectMake(300, 300, -200, -200));
CGContextAddRect(ref, CGRectMake(250, 250, -100, -100));
CGContextDrawPath(ref, kCGPathEOFill);
}
Simulator Screen Shot - iPhone SE (2nd generation) - 2020-05-08 at 16.10.06.png
非零环绕规则
- (void)drawRect:(CGRect)rect{
CGContextRef ref = UIGraphicsGetCurrentContext();
CGPoint outter_points[4] = {{100,100},{100,300},{300,300},{300,100}};
CGContextAddLines(ref, outter_points, 4);
CGPoint inner_points[4] = {{150,150},{250,150},{250,250},{150,250}};
CGContextAddLines(ref, inner_points, 4);
// CGContextFillPath(ref);
// 裁剪图片
CGContextClip(ref);
UIImage* image = [UIImage imageNamed:@"me"];
[image drawInRect:rect];
}
Simulator Screen Shot - iPhone SE (2nd generation) - 2020-05-08 at 16.15.12.png
网友评论