Skip to content

Instantly share code, notes, and snippets.

@Arthraim
Created February 22, 2013 01:22
Show Gist options
  • Save Arthraim/5010034 to your computer and use it in GitHub Desktop.
Save Arthraim/5010034 to your computer and use it in GitHub Desktop.
A practice of quartz. Draw something like table -///-
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor (context, 0, 0, 0, 1);
CGContextSetLineWidth(context, 1);
CGContextSetTextMatrix(context, CGAffineTransformMake(1.0,0.0, 0.0, -1.0, 0.0, 0.0));
int hours = 0;
float gap = self.height / 24;
for (float y = gap; y < self.height + gap / 2; y += gap) {
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), 0, y);
CGContextAddLineToPoint(context, self.width, y);
CGContextSelectFont(context,
"Helvetica-Bold",
gap,
kCGEncodingMacRoman);
CGContextSetCharacterSpacing(context, 0);
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextSetRGBStrokeColor(context, 0, 0, 0, 1);
const char *str = [[NSString stringWithFormat:@"%02d", hours] cStringUsingEncoding:NSUTF8StringEncoding];
CGContextShowTextAtPoint(context, 3, y, str, strlen(str));
hours++;
}
CGContextDrawPath(context, kCGPathStroke);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment