Skip to content

Instantly share code, notes, and snippets.

@nestserau
Created June 25, 2015 07:19
Show Gist options
  • Save nestserau/f46a8abbc69a9697180d to your computer and use it in GitHub Desktop.
Save nestserau/f46a8abbc69a9697180d to your computer and use it in GitHub Desktop.
Draw line in UIView
/* http://stackoverflow.com/questions/3128752/draw-line-in-uiview */
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
// Draw them with a 2.0 stroke width so they are a bit more visible.
CGContextSetLineWidth(context, 2.0f);
CGContextMoveToPoint(context, 0.0f, 0.0f); //start at this point
CGContextAddLineToPoint(context, 20.0f, 20.0f); //draw to this point
// and now draw the Path!
CGContextStrokePath(context);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment