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];
}