How does one draw a CGGradient on an enclosed path within a view? I have attempted to draw the gradient, however, it is drawn on the view itself, rather than only within a CGPath that I am filling inside the view. I would like to draw a gradient on the filled path only, and not on the view itself.
1 に答える
3
- Save the context's state.
- Set the path as a clip region in your context.
- Draw the gradient.
- Restore the context's state.
Example:
CGContextSaveGState(context);
CGContextAddPath(context, myPath);
CGContextClip(context);
CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, kNilOptions);
CGContextRestoreGState(context);
于 2012-07-30T07:03:25.343 に答える