0
如果我正在做一个简单的绘图,并且想要更改某些子路径的线宽/短划线,那么如何在不更改所有路径的情况下实现这一点?我尝试了一些使用CGContextSaveGState(context)的变体;但不能完全正确。这是否必须是完全不同的路径?我真的希望他们不要画阴影。绘制子路径时CG更改/保存环境
- (void)drawPitch:(CGContextRef)context {
// Push the context onto the stack
UIGraphicsPushContext(context);
//Reasonable defaults
CGRect pitchRect = CGRectMake(10, 10, 220, 344);
CGSize myShadowOffset = CGSizeMake(0,1);
float myColorValues[] = {0, 0, 0, 0.75};
CGColorRef myColor;
CGColorSpaceRef myColorSpace;
//Color Space
myColorSpace = CGColorSpaceCreateDeviceRGB();
myColor = CGColorCreate (myColorSpace, myColorValues);
// Set Stroke
CGContextSetRGBStrokeColor(context, 1, 1, 1, 0.9);
CGContextSetLineWidth(context, 4);
// Pitch Outline at width:4
CGContextAddRect(context, pitchRect);
CGContextSaveGState(context);
// Want this to be set width:2 just for the subpath
CGContextSetLineWidth(context, 2);
CGContextMoveToPoint(context, CGRectGetMinX(pitchRect), CGRectGetMinY(pitchRect) + (pitchRect.size.height * 0.50));
CGContextAddLineToPoint(context, CGRectGetMaxX(pitchRect), CGRectGetMinY(pitchRect) + (pitchRect.size.height * 0.50));
CGContextRestoreGState(context);
// Set Line Shadow
CGContextSetShadowWithColor(context, myShadowOffset, 10, myColor);
// Stroke path
CGContextStrokePath(context);
// Pop the contect back on the stack
UIGraphicsPopContext();
}