gpt4 book ai didi

objective-c - UIBezierPath 多线条颜色

转载 作者:行者123 更新时间:2023-11-30 13:29:15 27 4
gpt4 key购买 nike

我尝试用不同颜色绘制 UIBezierPath 线失败了。所有线条都会更改为当前选定的颜色。我所有的路径和信息都存储在一个名为pathInfo的NSMutableArray中。在路径信息中,我放入包含路径、颜色、宽度和线条类型的数组。除了所有线条都变成用户选择的颜色之外,这工作得很好。如果有任何帮助,我将不胜感激!

- (void)drawRect:(CGRect)rect {
UIBezierPath *drawPath = [UIBezierPath bezierPath];
drawPath.lineCapStyle = kCGLineCapRound;
drawPath.miterLimit = 0;

for (int i = 0; i < [pathInfo count]; i++){
NSArray *row = [[NSArray alloc] initWithArray:[pathInfo objectAtIndex:i]];
NSLog(@"Path: %@",[row objectAtIndex:0]);
NSLog(@"Color: %@",[row objectAtIndex:1]);
NSLog(@"Width: %@",[row objectAtIndex:2]);
NSLog(@"Type: %@",[row objectAtIndex:3]);

//width
drawPath.lineWidth = [[row objectAtIndex:2] floatValue];

//color
[[row objectAtIndex:1] setStroke];

//path
[drawPath appendPath:[row objectAtIndex:0]];

}

UIBezierPath *path = [self pathForCurrentLine];
if (path)
[drawPath appendPath:path];

[drawPath stroke];
}

- (UIBezierPath*)pathForCurrentLine {
if (CGPointEqualToPoint(startPoint, CGPointZero) && CGPointEqualToPoint(endPoint, CGPointZero)){
return nil;
}

UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:startPoint];
[path addLineToPoint:endPoint];

return path;

}

最佳答案

描边/填充颜色仅影响-描边命令。它们不会影响 -appendPath: 命令。路径不包含每段颜色信息。

如果您需要多色线条,则需要分别描边每种颜色。

关于objective-c - UIBezierPath 多线条颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36760600/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com