Draw a rectangle for IOS development (82)

Source: Internet
Author: User

1 Preface
Use CGPathAddRect to add a rectangle to the path and draw the path in the graphic environment.


2. code example
ZYViewControllerView. m

 

[Plain]-(void) drawRect :( CGRect) rect {
// Create a graphical path handle
CGMutablePathRef path = CGPathCreateMutable ();
// Set the boundary of the rectangle
CGRect rectangle = CGRectMake (10.0f, 10.0f, 200366f, 300366f );
// Add a rectangle to the path
CGPathAddRect (path, NULL, rectangle );
// Obtain the context handle
CGContextRef currentContext = UIGraphicsGetCurrentContext ();
// Add the path to the context
CGContextAddPath (currentContext, path );
// Fill color
[[UIColor colorWithRed: 0.20f green: 0.60f blue: 0.80f alpha: 1.0f] setFill];
// Set the paint brush color
[[UIColor brownColor] setStroke];
// Set the border line width
CGContextSetLineWidth (currentContext, 5.0f );
// Draw
CGContextDrawPath (currentContext, kCGPathFillStroke );
/* Release path */
CGPathRelease (path );
}

Related Article

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.