我嘗試使用不同的顏色繪製UIBezierPath行會讓我失望。所有線都變爲當前選擇的顏色。我所有的路徑和信息都存儲在一個名爲pathInfo的NSMutableArray中。在路徑信息中,我放入包含路徑,顏色,寬度和類型行的數組中。這工作正常,除了所有的行都變成用戶選擇的顏色。我會很感激任何幫助!UIBezierPath多行顏色
- (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;
}
如果可能的話,請通過我你的完整代碼這一點。其實我也面臨同樣的問題。但我正在使用touchesBegan,touchesMoved和touchesEnd方法。我無法做到。 – Abha 2016-06-27 11:09:12