How can I draw a line by using CGPath ?
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With