UIBezierPath不同的颜色

问题描述:

我能在我的应用程序中使用UIBezierPath进行绘制。现在我添加了一个UIColor变量,以便用户按下按钮可以选择不同的颜色。当用户改变颜色并且开始用新颜色绘制时,所有已经绘制的路径都具有新的颜色。UIBezierPath不同的颜色

如何告诉对象不要更改已经绘制的路径的颜色?

这是我的代码。任何代码的例子非常感谢! :)

(我有我的UIColor变量中的appDelegate蓄能和我打电话从其他viewControlle刷新方法。

- (id)initWithFrame:(CGRect)frame 
{ 
self = [super initWithFrame:frame]; 
if (self) { 

    AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 


    self.backgroundColor = [UIColor whiteColor]; 
    myPath = [[UIBezierPath alloc] init]; 
    myPath.lineCapStyle = kCGLineCapRound; 
    myPath.miterLimit = 0; 
    myPath.lineWidth = 5; 

    brushPattern = app.currentColor; 

} 
    return self; 
} 
-(void)refresh { 
    AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 

    brushPattern = app.currentColor; 
} 



- (void)drawRect:(CGRect)rect { 
    [brushPattern setStroke]; 
    for (UIBezierPath *_path in pathArray) 
    [_path strokeWithBlendMode:kCGBlendModeNormal alpha:1.0]; 
} 


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    myPath = [[UIBezierPath alloc] init]; 
    myPath.lineWidth = 5; 

    UITouch *mytouch = [[touches allObjects] objectAtIndex:0]; 
    [myPath moveToPoint:[mytouch locationInView:self]]; 
    [pathArray addObject:myPath]; 
} 

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    UITouch *mytouch = [[touches allObjects] objectAtIndex:0]; 
    [myPath addLineToPoint:[mytouch locationInView:self]]; 
    [self setNeedsDisplay]; 
} 

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 

} 
+0

你已经得到任何解决方案?如果您已经然后回答后,因此,这将是有帮助给别人.. – 2013-04-08 13:33:26

+0

不,对不起。我需要改变系统... – BalestraPatrick 2013-04-08 15:40:03

我找到了一个演示代码为..

请检查此它是否会有所帮助你..

Smooth Line链接

+0

谢谢!它看起来真棒:) – BalestraPatrick 2013-04-09 09:45:39

+0

然后接受答案..所以其他人可以从这里得到帮助.. – 2013-04-09 14:54:42