1 Preface
Construct and draw paths to draw any shape in the graphic environment.
2. code example
ZYViewControllerView. m
[Plain]-(void) drawRect :( CGRect) rect {
// Create a new CGMutablePathRef variable path and return its handle.
CGMutablePathRef path = CGPathCreateMutable ();
/* How big is our screen? We want the X to cover the whole screen */
// The range is the entire Screen
CGRect screenBounds = [[UIScreen mainScreen] bounds];
// Draw a path from the upper left corner to move the current paint position in the path to the point specified by the CGPoint type parameter.
CGPathMoveToPoint (path, NULL, screenBounds. origin. x, screenBounds. origin. y );
// Draw a line segment from the current position of the paint brush from the upper left corner to the lower right corner.
CGPathAddLineToPoint (path, NULL, screenBounds. size. width, screenBounds. size. height );
// Start another point from the upper right corner
CGPathMoveToPoint (path, NULL, screenBounds. size. width, screenBounds. origin. y );
// From the upper right corner to the lower left corner
CGPathAddLineToPoint (path, NULL, screenBounds. origin. x, screenBounds. size. height );
// Obtain the context of the current image
CGContextRef currentContext = UIGraphicsGetCurrentContext ();
/* Add the path to the context so we candraw it later */
// Add a path to the path context and add a path to the graphic environment (specified by a path handle). The path is ready to be drawn.
CGContextAddPath (currentContext, path );
// Set blue
[[UIColor blueColor] setStroke];
// Draw a specified path in the graphic environment
/* KCGPathStroke
Draw a line to mark the border or edge of the path and use the selected drawing color.
KCGPathFill
Fill the area surrounded by paths with the selected fill color.
KCGPathFillStroke
Combine drawing and filling. Fill the path with the current fill color and draw the path boundary with the current drawing color. The following shows an example of using this method.
*/
CGContextDrawPath (currentContext, kCGPathStroke );
// Release path
CGPathRelease (path );
}
-(Void) drawRect :( CGRect) rect {
// Create a new CGMutablePathRef variable path and return its handle.
CGMutablePathRef path = CGPathCreateMutable ();
/* How big is our screen? We want the X to cover the whole screen */
// The range is the entire Screen
CGRect screenBounds = [[UIScreen mainScreen] bounds];
// Draw a path from the upper left corner to move the current paint position in the path to the point specified by the CGPoint type parameter.
CGPathMoveToPoint (path, NULL, screenBounds. origin. x, screenBounds. origin. y );
// Draw a line segment from the current position of the paint brush from the upper left corner to the lower right corner.
CGPathAddLineToPoint (path, NULL, screenBounds. size. width, screenBounds. size. height );
// Start another point from the upper right corner
CGPathMoveToPoint (path, NULL, screenBounds. size. width, screenBounds. origin. y );
// From the upper right corner to the lower left corner
CGPathAddLineToPoint (path, NULL, screenBounds. origin. x, screenBounds. size. height );
// Obtain the context of the current image
CGContextRef currentContext = UIGraphicsGetCurrentContext ();
/* Add the path to the context so we candraw it later */
// Add a path to the path context and add a path to the graphic environment (specified by a path handle). The path is ready to be drawn.
CGContextAddPath (currentContext, path );
// Set blue
[[UIColor blueColor] setStroke];
// Draw a specified path in the graphic environment
/* KCGPathStroke
Draw a line to mark the border or edge of the path and use the selected drawing color.
KCGPathFill
Fill the area surrounded by paths with the selected fill color.
KCGPathFillStroke
Combine drawing and filling. Fill the path with the current fill color and draw the path boundary with the current drawing color. The following shows an example of using this method.
*/
CGContextDrawPath (currentContext, kCGPathStroke );
// Release path
CGPathRelease (path );
}
Hidden Status Bar
In this example, I want to hide the program status bar: find Info. plist, add a uistatusbarhidkey, and set its value to YES.