使用CGPath绘制一条线 [英] draw a line by using CGPath

查看:186
本文介绍了使用CGPath绘制一条线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用CGPath绘制一条线?

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.

在路径的左上角和右下角(在iOS上)之间绘制一条带有路径的对角线在UIView的drawRect:

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);
}

这篇关于使用CGPath绘制一条线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆