Detecting if UIColor was created with colorWithPatternImage

旧巷老猫 提交于 2020-01-24 11:34:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!