1
我有许多'line'对象 - 每个对象存储关于使用Core Graphics绘制的线条的信息。问题是,虽然可能有多个线对象,每个线对象都具有唯一的颜色和笔触宽度,但所有线都在SAME颜色和笔触宽度下绘制。试图为每个笔画设置独特的CoreGraphics(iphone)状态
每一行对象都具有诸如笔触颜色,笔画宽度和CGPoint的NSMutableArray等属性。在我的drawRect方法中,我有一个NSEnumerator迭代器,它处理每个线对象的每个CGPoint以及一个while循环,它可以将上面的对象集合到每一行中。在每条新线的开始处,我使用CGContext方法(下面的代码)设置笔触颜色和粗细。 如何绘制各自独特的颜色?
- (void)drawRect:(CGRect)rect {
if(hasDrawnBefore){
myContext = UIGraphicsGetCurrentContext();
CGContextSetLineCap(myContext, kCGLineCapRound);
int numberOfLines = [myLines count];
int h = 0;
while(h < numberOfLines){
CGContextSetStrokeColorWithColor(myContext, [[[myLines objectAtIndex:h] lineColor] CGColor]);
CGContextSetLineWidth(myContext, [[myLines objectAtIndex:h] lineThickness]);
NSLog(@"<---------------------- Changed Color and Stroke-Width! ------------------------>");
NSEnumerator *myEnumerator = [[[myLines objectAtIndex:h] linePoints] objectEnumerator];
PointObject* object;
int enumIndex = 0;
while ((object = [myEnumerator nextObject])) {
if(enumIndex == 0){
CGContextMoveToPoint(myContext, object.coordX, object.coordY);
}else{
CGContextAddLineToPoint(myContext, object.coordX, object.coordY);
}
enumIndex++;
}
NSLog(@"Just Iterated on the %i th line of %i lines", h, numberOfLines);
h++;
}
CGContextStrokePath(myContext);
NSLog(@"DRAWING");
}else{
NSLog(@"No Drawings Yet");
}
}