【问题标题】:UIBezierPath different colorsUIBezierPath 不同颜色
【发布时间】:2013-04-09 13:12:41
【问题描述】:

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

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

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

(我的 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 {

 }

【问题讨论】:

  • 你有什么解决办法吗?如果您已经在答案中发布,那么它对其他人会有所帮助..
  • 不,抱歉。我需要更改系统...

标签: xcode uibezierpath


【解决方案1】:

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

如果对你有帮助,请检查一下..

Smooth Line链接

【讨论】:

  • 谢谢!它看起来棒极了:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多