Question

I need to get a CGColor from a CGGradientRef, and use the color as a stroke colour in a drawing app for iOS 7. Is that possible?

Was it helpful?

Solution

You could draw the gradient to an image context, get the pixel buffer for the image, then create a color from that pixel (see this post).

Otherwise, CGGradientRef is an opaque type, and there isn't any way to get information out of it. For my own apps, I've also created a wrapper object around CGGradientRef that creates the gradient and stores the colors / locations it was created with.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top