Created
July 25, 2012 19:42
-
-
Save C4Examples/3178152 to your computer and use it in GitHub Desktop.
lineCap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // C4WorkSpace.m | |
| // Examples | |
| // | |
| // Created by Travis Kirton on 12-07-19. | |
| // | |
| #import "C4WorkSpace.h" | |
| @interface C4WorkSpace () | |
| -(void)setupLines; | |
| -(void)setupGridLines; | |
| -(void)setupLabels; | |
| @end | |
| @implementation C4WorkSpace { | |
| C4Shape *line1, *line2, *line3; | |
| CGPoint linePoints[2]; | |
| CGFloat x1, x2; | |
| } | |
| -(void)setup { | |
| //create 2 x coordinates | |
| x1 = self.canvas.width/4; | |
| x2 = self.canvas.width*3/4; | |
| [self setupLines]; | |
| [self setupGridLines]; | |
| [self setupLabels]; | |
| } | |
| -(void)setupLines { | |
| //set the points for the first line | |
| linePoints[0] = CGPointMake(x1, self.canvas.height/4); | |
| linePoints[1] = CGPointMake(x2, self.canvas.height/4); | |
| //create and style the first line (no need to set the lineCap because we show the default here) | |
| line1 = [C4Shape line:linePoints]; | |
| line1.lineWidth = 30.0f; | |
| //set the points for the first line | |
| linePoints[0] = CGPointMake(x1, self.canvas.height/2); | |
| linePoints[1] = CGPointMake(x2, self.canvas.height/2); | |
| //create and style the second line | |
| line2 = [C4Shape line:linePoints]; | |
| line2.strokeColor = C4BLUE; | |
| line2.lineWidth = 30.0f; | |
| line2.lineCap = CAPSQUARE; | |
| //set the points for the first line | |
| linePoints[0] = CGPointMake(x1, self.canvas.height*3/4); | |
| linePoints[1] = CGPointMake(x2, self.canvas.height*3/4); | |
| //create and style the third line | |
| line3 = [C4Shape line:linePoints]; | |
| line3.strokeColor = C4GREY; | |
| line3.lineWidth = 30.0f; | |
| line3.lineCap = CAPROUND; | |
| //add all the lines to the canvas | |
| [self.canvas addShape:line1]; | |
| [self.canvas addShape:line2]; | |
| [self.canvas addShape:line3]; | |
| } | |
| -(void)setupGridLines { | |
| //create a single point array to set as the dash pattern for the grid lines | |
| CGFloat dashPattern[1] = {2.0f}; | |
| //offset x1 and x2 to sharpen the grid lines | |
| x1 += 0.5f; | |
| x2 += 0.5f; | |
| C4Shape *gridLine1, *gridLine2; | |
| //set the points for the first grid line | |
| linePoints[0] = CGPointMake(x1, 0); | |
| linePoints[1] = CGPointMake(x1, self.canvas.height); | |
| //create the first line and style it with width and a dash pattern | |
| gridLine1 = [C4Shape line:linePoints]; | |
| gridLine1.lineWidth = 1.0f; | |
| [gridLine1 setDashPattern:dashPattern pointCount:1]; | |
| //set the points for the second grid line | |
| linePoints[0] = CGPointMake(x2, 0); | |
| linePoints[1] = CGPointMake(x2, self.canvas.height); | |
| //create the second line and style it with width and a dash pattern | |
| gridLine2 = [C4Shape line:linePoints]; | |
| gridLine2.lineWidth = 1.0f; | |
| [gridLine2 setDashPattern:dashPattern pointCount:1]; | |
| //add the lines to the canvas | |
| [self.canvas addShape:gridLine1]; | |
| [self.canvas addShape:gridLine2]; | |
| } | |
| -(void)setupLabels { | |
| //create a font to use for all the labels | |
| C4Font *f = [C4Font fontWithName:@"ArialRoundedMTBold" size:20]; | |
| //create, style and add the first label, with text describing its lineCap type | |
| C4Label *l = [C4Label labelWithText:@"CAPBUTT (default)" font:f]; | |
| l.textColor = [UIColor whiteColor]; | |
| l.center = line1.center; | |
| [self.canvas addLabel:l]; | |
| //create, style and add the second label, with text describing its lineCap type | |
| l = [C4Label labelWithText:@"CAPSQUARE" font:f]; | |
| l.textColor = [UIColor whiteColor]; | |
| l.center = line2.center; | |
| [self.canvas addLabel:l]; | |
| //create, style and add the third label, with text describing its lineCap type | |
| l = [C4Label labelWithText:@"CAPROUND" font:f]; | |
| l.textColor = [UIColor whiteColor]; | |
| l.center = line3.center; | |
| [self.canvas addLabel:l]; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment