Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

draw a line by using CGPath [closed]

How can I draw a line by using CGPath ?

like image 819
Andrey Avatar asked Mar 25 '11 15:03

Andrey


1 Answers

As you didn't really specify more than how to draw a line with a path, I'll just give you an example.

Drawing a diagonal line between the top left corner and the bottom right (on iOS) with a path in a UIView's drawRect:

- (void)drawRect:(CGRect)rect { 
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, 0, 0);
    CGPathAddLineToPoint(path, NULL, CGRectGetMaxX(rect), CGRectGetMaxY(rect));
    CGPathCloseSubpath(path);
    CGContextAddPath(ctx, path);
    CGContextSetStrokeColorWithColor(ctx,[UIColor whiteColor].CGColor);
    CGContextStrokePath(ctx);
    CGPathRelease(path);
}
like image 124
Erik Tjernlund Avatar answered Sep 23 '22 01:09

Erik Tjernlund