Metabble
Metabble

Reputation: 11841

Stroking a CGPath with a gradient?

I've been looking into this for a while now, and as a beginner, I can't seem to get it done. What I want to do is take a simple gradient, and use it to stroke a CGPath. I tried using CGContextSetStokePattern with a PNG the width of the line and one pixel tall containing my desired gradient, but this tiles the pattern, whilst I'd rather have it drawn along the path like a brush. Closest thing I can think of would be the Styler from Pokémon Ranger.

enter image description here

Essentially, I'd like my line to start out one color in the middle and move towards another at the edges. There's probably a simple way of doing this, but I cannot for the life of me figure out how.

Much thanks to anyone who can help me. :)

Upvotes: 1

Views: 898

Answers (1)

rob mayoff
rob mayoff

Reputation: 385860

There's no built-in support for stroking a path in that way.

You could try to fake it by stroking the path multiple times, with each stroke having a narrow line width than the prior stroke and a different color, and maybe different shadow settings too. Of course stroking it repeatedly will take longer than stroking it once.

Upvotes: 2

Related Questions