UIBezierPath有多种颜色?

时间:2013-03-26 06:31:10

标签: iphone ios uibezierpath

我正在处理我使用UIBezierPath进行绘制的项目。我的问题是,当我改变路径的颜色时,整个UIBezierPath颜色会发生变化。我想问一下是否可以用多行改变UIBezierPath的颜色。

问候

1 个答案:

答案 0 :(得分:2)

对于一个单独的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:这只是一个例子。我还没有检查过这段代码,但它应该可以进行一些改动。

相关问题