【发布时间】:2012-05-19 19:27:30
【问题描述】:
在 iOS 上,我们可以使用 drawRect 画一条线
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextBeginPath (context);
CGContextMoveToPoint(context, 0, 0);
CGContextAddLineToPoint(context, 100, 100);
CGContextStrokePath(context);
但如果我们删除上面的代码,我们也可以绘制一个矩形,然后使用:
UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 100, 100)];
[path stroke];
两个相关问题:
1) 为什么UIBezierPath 不需要获取或使用当前上下文?
2) 如果我有两个上下文:一个用于屏幕,一个是位图上下文,那么如何判断 UIBezierPath 绘制到哪个上下文?我以为它可能是UIGraphicsSetCurrentContext,但它不存在。
【问题讨论】:
标签: iphone ios uikit core-graphics