Question

SITUATION

I've drawn a thin line via CGContextAddLineToPoint and CGContextStrokePath. I added a red shadow via CGContextSetShadowWithColor.

DESIRED BEHAVIOR

No matter what value I set for the blur, the red shadow was too weak. I would like the red shadow to be much much stronger.

NOTE

The white line with red shadow is placed on top of an image, not a flat color, so I can't use a flat color to fake it.

Also, the white line can be curved (I use CGContextAddQuadCurveToPoint).

WHAT I TRIED

Playing around with CGContextSetLineWidth, I found that increasing the width made the red shadow more noticeable. However, the white line was then too thick.

I then tried splitting it the drawing into two parts with the shadow using a larger line width. When I tried drawing just the shadow with [[UIColor clearColor] setStroke], the shadow wasn't drawn at all.

I then tried drawing just the shadow with [[UIColor colorWithRed:1 green:0 blue:0 alpha:0.1] setStroke] but having an alpha on the stroke ALSO affects the alpha of the shadow, so the shadow was still too weak.

I tried following iOS Core Graphics: Draw ONLY shadows of a CGPath but I got a weird effect where not only did my shadows not show, but the line was fading from red to black. I wasn't sure what was going on.

Help would be greatly appreciated.

Était-ce utile?

La solution

I ended up following CGContextDrawRadialGradient For Non-Circular Glow. Essentially I redrew the line on top of itself multiple times until the glow looked strong enough. I also rasterized it in the hopes that the performance hit won't be too harsh.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top