Search code examples
iosobjective-cuicolor

Detecting if UIColor was created with colorWithPatternImage


I have a UIColor that is passed into me. I need to detect if it is a plain color (e.g. created with colorWithRed:green:blue:alpha:) or if it is a color that was created with colorWithPatternImage.

How can I tell what kind of color a UIColor is, simple color or otherwise?


Solution

  • You should be able to use the CGColorGetPattern function with the CGColor property, and check for NULL.

    if( CGColorGetPattern( myColor.CGColor ) != NULL ) {}