在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
,但它不存在。
UIGraphicsPushContext(myBitmapContext);
来开始在位图上下文中绘制? - nonopolarity