Skip to content

Instantly share code, notes, and snippets.

@ferbass
Created October 30, 2013 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ferbass/7231889 to your computer and use it in GitHub Desktop.
Save ferbass/7231889 to your computer and use it in GitHub Desktop.
Objective-C ZigZag line with CoreGraphics
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [[UIColor colorWithRed:241.0/255.0 green:241.0/255.0 blue:238.0/255.0 alpha:1] CGColor]);
CGContextSetLineWidth(context, 0.6);
CGContextMoveToPoint(context, CGRectGetMinX(rect), CGRectGetMaxY(rect) - 5);
CGContextSetShouldAntialias(context, YES);
for (int i = 0; i < 320; i++) {
float x = (CGRectGetMinX(rect) + 7) * i;
float y = CGRectGetMaxY(rect) - 5;
CGContextAddLineToPoint(context, x, y);
CGContextAddLineToPoint(context, x + 1, y);
CGContextAddLineToPoint(context, x + 4, CGRectGetMaxY(rect));
CGContextSetShouldAntialias(context, NO);
}
CGContextStrokePath(context);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment