So, you cannot do this directly, because the shadow reflects the path, so if you make the path transparent, the shadow will also be transparent. There are some workarounds that I can come up with (depending on what you are doing), but one sneaky way is to just draw a shadow far enough below the path that you can just draw, basically by erasing it. For example, if the background is white, this will accomplish what you want:
- (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1.0); CGContextSetLineWidth(context, 10.0); CGContextMoveToPoint(context, 10.0, 30.0); CGContextAddLineToPoint(context, 310.0, 30.0); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGFloat components[4] = {0.0, 0.0, 0.0, 1.0}; CGColorRef shadowColor = CGColorCreate(colorSpace, components); CGContextSetShadowWithColor(context, CGSizeMake(0.0f,20.0f), 4.0, shadowColor); CGContextStrokePath(context); CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0); CGContextSetLineWidth(context, 10.0); CGContextMoveToPoint(context, 10.0, 30.0); CGContextAddLineToPoint(context, 310.0, 30.0); CGContextStrokePath(context); }
hope this helps.
pho0
source share