IOS development (80)

Source: Internet
Author: User

1 Preface
Obtain the graphic environment, and use the CGContextMoveToPoint and CGContextAddLineToPoint functions to draw lines.


2. code example
ZYViewControllerView. m

 

[Plain]
-(Void) drawRect :( CGRect) rect {
[Self drawRooftopAtTopPointof: CGPointMake (160.0f, 40366f) textToDisplay: @ "Miter"
LineJoin: kCGLineJoinMiter];
[Self drawRooftopAtTopPointof: CGPointMake (160.0f, 180.0f) textToDisplay: @ "Bevel"
LineJoin: kCGLineJoinBevel];
[Self drawRooftopAtTopPointof: CGPointMake (160.0f, 3200000f) textToDisplay: @ "Round"
LineJoin: kCGLineJoinRound];
}
/*
ParamTopPoint: a point at which the top is located
TextToDisplay: Text displayed in
LineJoin: The join type to be used.
KCGLineJoinMiter
The joint point is a sharp angle. This is the default join type.
KCGLineJoinBevel
Corner Joint
KCGLineJoinRound
The joint point is rounded.
*/
-(Void) drawRooftopAtTopPointof :( CGPoint) paramTopPoint textToDisplay :( NSString *) paramText
LineJoin :( CGLineJoin) paramLineJoin {
/* Set the line color */
[[UIColor brownColor] set];
// Obtain the current image Context
CGContextRef currentContext = UIGraphicsGetCurrentContext ();
// Set the connection type
CGContextSetLineJoin (currentContext, paramLineJoin );
// Set the line width
CGContextSetLineWidth (currentContext, 20366f );
// Set the start point position
CGContextMoveToPoint (currentContext, paramTopPoint. x-140, paramTopPoint. y + 100 );
// Set the end point
CGContextAddLineToPoint (currentContext, paramTopPoint. x, paramTopPoint. y );
// Set another endpoint
CGContextAddLineToPoint (currentContext, paramTopPoint. x + 140, paramTopPoint. y + 100 );
// Draw a line
CGContextStrokePath (currentContext );
[[UIColor blackColor] set];
/* Write text */
CGPoint drawingPoint = CGPointMake (paramTopPoint. x-401_f,
ParamTopPoint. y + 601_f );
[ParamText drawAtPoint: drawingPoint withFont: [UIFont boldSystemFontOfSize: 30366f];
}

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.