我正在开发一个正在使用 UIBezierPath
的项目用于绘图。我的问题是,当我更改路径的颜色时,整个 UIBezierPath
颜色变化。我想问UIBezierPath
的颜色可以改吗有多行。
问候
最佳答案
对于一个 UIBezier 路径,你不能 AFAIK
你可以做这样的事情
/////将其添加到drawRect
for (NSMutableDictionary *dic in pathArray) {
UIBezierPath *_path = [dic valueForKey:@"path"];
[[dic valueForKey:@"fColor"] setFill];
[[dic valueForKey:@"sColor"] setStroke];
[_path stroke];
}
在触摸事件中填充数组
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
self.currentPath=[[UIBezierPath alloc]init];
self.currentPath.lineWidth=5;
self.currentPath.miterLimit=-10;
self.currentPath.lineCapStyle = kCGLineCapRound;
self.currentPath.flatness = 0.0;
UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
[self.currentPath moveToPoint:[mytouch locationInView:self]];
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
[dic setObject:currentfColor forKey:@"fColor"];
[dic setObject:currentsColor forKey:@"sColor"];
[dic setObject:self.currentPath forKey:@"path"];
[pathArray addObject:dic];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
[self.currentPath addLineToPoint:[touch locationInView:self.view]];
[self.view setNeedsDisplay];
}
PS:这只是一个例子。我还没有检查过这段代码,但它应该可以工作,可能需要一些修改。
关于iphone - UIBezierPath 具有多种颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15630759/