我可以查询是否 UIColor
通过检查是一种模式 CGColor
它包裹的实例, CGColorGetPattern()
函数返回模式(如果存在),或 null
如果它不是图案颜色。
CGPatternCreate()
方法需要一个 bounds
在创建图案时,此值定义图案图块的大小 (在Quartz用语中称为单元格)。
我将如何从a中检索此图案大小 UIColor
或支持 CGPattern
一旦它被创建了?
我可以查询是否 UIColor
通过检查是一种模式 CGColor
它包裹的实例, CGColorGetPattern()
函数返回模式(如果存在),或 null
如果它不是图案颜色。
CGPatternCreate()
方法需要一个 bounds
在创建图案时,此值定义图案图块的大小 (在Quartz用语中称为单元格)。
我将如何从a中检索此图案大小 UIColor
或支持 CGPattern
一旦它被创建了?
如果您的应用程序仅用于内部分发,则可以使用私有API。如果你看看CoreGraphics框架中定义的函数,你会发现有很多函数,其中有一个函数被调用 CGPatternGetBounds
:
otool -tV /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics | egrep "^_CGPattern"
您只需在框架上进行一些函数查找,并通过函数指针使用它。
标题包括:
#include <dlfcn.h>
函数指针:
typedef CGRect (*CGPatternGetBounds)(CGPatternRef pattern);
检索函数的代码:
void *handle = dlopen("/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics", RTLD_NOW);
CGPatternGetBounds getBounds = (CGPatternGetBounds) dlsym(handle, "CGPatternGetBounds");
检索边界的代码:
UIColor *uicolor = [UIColor groupTableViewBackgroundColor]; // Select a pattern color
CGColorRef color = [uicolor CGColor];
CGPatternRef pattern = CGColorGetPattern(color);
CGRect bounds = getBounds (pattern); // This result is a CGRect(0, 0, 84, 1)
我不认为有可能从CGPatternRef中获取界限,如果这就是你所要求的
似乎没有任何方法可以直接从CGPatternRef中检索任何信息。
如果你必须这样做,可能唯一的方法(除了戳CGPattern结构的私有内容,可能算作“使用私有API”)是将模式渲染到足够大的图像缓冲区,然后检测重复的子单元。 在图像中查找重复的图案/图像 可能是一个很好的起点。
如果您的应用程序仅用于内部分发,则可以使用私有API。如果你看看CoreGraphics框架中定义的函数,你会发现有很多函数,其中有一个函数被调用 CGPatternGetBounds
:
otool -tV /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics | egrep "^_CGPattern"
您只需在框架上进行一些函数查找,并通过函数指针使用它。
标题包括:
#include <dlfcn.h>
函数指针:
typedef CGRect (*CGPatternGetBounds)(CGPatternRef pattern);
检索函数的代码:
void *handle = dlopen("/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics", RTLD_NOW);
CGPatternGetBounds getBounds = (CGPatternGetBounds) dlsym(handle, "CGPatternGetBounds");
检索边界的代码:
UIColor *uicolor = [UIColor groupTableViewBackgroundColor]; // Select a pattern color
CGColorRef color = [uicolor CGColor];
CGPatternRef pattern = CGColorGetPattern(color);
CGRect bounds = getBounds (pattern); // This result is a CGRect(0, 0, 84, 1)
我不认为有可能从CGPatternRef中获取界限,如果这就是你所要求的
似乎没有任何方法可以直接从CGPatternRef中检索任何信息。
如果你必须这样做,可能唯一的方法(除了戳CGPattern结构的私有内容,可能算作“使用私有API”)是将模式渲染到足够大的图像缓冲区,然后检测重复的子单元。 在图像中查找重复的图案/图像 可能是一个很好的起点。
制作自己的颜色类来存储边界并允许您通过属性访问它们可能是一个可行的解决方案。
似乎不可能从UIColor中提取模式边界。