我想在uiview中绘制多个UIBezierPath,具有不同的笔画和填充颜色.
这是代码
- (void)drawRect:(CGRect)rect { context = UIGraphicsGetCurrentContext(); [[UIColor grayColor] setFill]; [[UIColor greenColor] setStroke]; UIBezierPath *aPath = [[UIBezierPath alloc] init]; [aPath moveToPoint:CGPointMake(227,34.25)]; [aPath addLineToPoint:CGPointMake(298.25,34.75)]; [aPath addLineToPoint:CGPointMake(298.5,82.5)]; [aPath addLineToPoint:CGPointMake(251,83)]; [aPath addLineToPoint:CGPointMake(251,67.5)]; [aPath addLineToPoint:CGPointMake(227.25,66.75)]; [aPath closePath]; aPath.lineWidth = 2; [aPath fill]; [aPath stroke]; UIBezierPath* aPath2 = [[UIBezierPath alloc] init]; [aPath2 moveToPoint:CGPointMake(251.25,90.5)]; [aPath2 addLineToPoint:CGPointMake(250.75,83.25)]; [aPath2 addLineToPoint:CGPointMake(298.5,83)]; [aPath2 addLineToPoint:CGPointMake(298.5,90.25)]; [aPath2 closePath]; aPath2.lineWidth = 2; [aPath2 fill]; [aPath2 stroke]; [paths addObject:aPath2];
问题是笔画和填充颜色是在当前上下文中设置的.
在同一个CGContextRef中可以用不同的颜色绘制不同的UIBezierPath吗?
或者我必须在单独的uiview中绘制每个UIBezierPath?
解决方法
你应该添加
[desiredStrokeColor setStroke]; [desiredFillColor setFill];
表明这些是在这种情况下必须进一步使用的新颜色.你每次打电话之前都应该这样做
[aNewPath fill]; [aNewPath stroke];
以便用这些颜色绘制路径.
不需要为每个贝塞尔路径使用新的视图.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。