问题
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?
回答1:
You should be able to use the CGColorGetPattern function with the CGColor property, and check for NULL.
if( CGColorGetPattern( myColor.CGColor ) != NULL ) {}
回答2:
Another solution is to check the color space model:
if (CGColorSpaceGetModel(CGColorGetColorSpace(myColor.CGColor)) == kCGColorSpaceModelPattern))
{}
来源:https://stackoverflow.com/questions/14391577/detecting-if-uicolor-was-created-with-colorwithpatternimage