Construction Path of IOS development (81)

Source: Internet
Author: User

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.


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.