iphone - UIBezierPath 具有多种颜色?

标签 iphone ios uibezierpath

我正在开发一个正在使用 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/

相关文章:

iphone - 如何使 UINavigationBar 不下推 View ?

ios - UIView 上的圆角仅适用于 iPhone 8、iPhone 6s、iPhone 6s plus、iPhone 6 等少数模拟器

php - NSURLMutableRequest 与 POST 方法和 PHP

ios - 如何将 swiftyJSON dictionaryValue 用作 UILabel 的可用字符串?

iphone - 寻找自定义手势的方向,例如滑动滚动

swift - 如何在父 CALayer 中居中 CALayer

ios - 使用 UIBezierPath 绘制自定义 View 会导致非对称形状

ios - 防止iPad上的显示器旋转

iPhone 音频单元在后台录音,如何

iphone - 像素化的 iphone UIImageView