Quartz2D summary, iosquartz2d
I have lost my mind. At least I have forgotten the context. I would like to summarize it and remember this interview.
The Quartz2D API comes from Core Graphics (that is why CGContextRef starts with CG) and needs to import CoreGraphics (?)
Graphical context: A CGContextRef type data
Role of the graphic context:
1. Save drawing information and drawing status
2. Determine the output target (where to draw) (the output target can be a PDF file, Bitmap, or display window ).
Bitmap Graphics ContextPDF Graphics ContextWindow Graphics ContextLayer Graphics ContextPrinter Graphics Context
Draw a view by yourself
Steps:
1. Create a new class inherited from UIView
2. Implement-(void) drawRect :( CGRect) rect method, and obtain the graph context of the current view in this method
3. Create your own drawing path and draw the Image Based on the path
4. Use the graphic context to render all the drawn content to the view
Of course, for example, the Bitmap graphic context does not have to be in-(void) drawRect :( CGRect) rect, you can directly create one:
// Create a bitmap context transform (CGSizeMake (200,200), NO, 0); // obtain the bitmap context CGContextRef ctr = UIGraphicsGetCurrentContext (); // draw the circle CGContextAddEllipseInRect (ctr, CGRectMake (50, 50,100,100); // render CGContextStrokePath (ctr); // obtain the image UIImage * img = UIGraphicsGetImageFromCurrentImageContext () from the context (); UIImageView * imageView = [[UIImageView alloc] initWithImage: img]; CGRect frame = imageView. frame; frame. origin = CGPointMake (50, 50); imageView. frame = frame; [self. view addSubview: imageView];
To be continued...
Part reference from: http://www.jianshu.com/p/eecffec3b7af