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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top