Created
February 16, 2013 11:06
-
-
Save cook/4966449 to your computer and use it in GitHub Desktop.
如何在Quard 2D使用clipping的办法绘制。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)drawRect:(CGRect)rect | |
{ | |
// assume the background color is white | |
CGContextRef con = UIGraphicsGetCurrentContext(); | |
// punch triangle hole in context clipping region | |
CGContextMoveToPoint(con, 90, 100); | |
CGContextAddLineToPoint(con, 100, 90); | |
CGContextAddLineToPoint(con, 110, 100); | |
CGContextClosePath(con); | |
CGContextAddRect(con, CGContextGetClipBoundingBox(con)); | |
CGContextEOClip(con); | |
// draw the vertical line, add its shape to the clipping region | |
CGContextMoveToPoint(con, 100, 100); | |
CGContextAddLineToPoint(con, 100, 19); | |
CGContextSetLineWidth(con, 20); | |
CGContextStrokePath(con); | |
// draw the red triangle, the point of the arrow | |
CGContextSetFillColorWithColor(con, [[UIColor redColor] CGColor]); | |
CGContextMoveToPoint(con, 80, 25); | |
CGContextAddLineToPoint(con, 100, 0); | |
CGContextAddLineToPoint(con, 120, 25); | |
CGContextFillPath(con); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment