UIColor colorWithPatternImage更改图像的颜色

时间:2012-09-12 17:55:24

标签: ios uicolor

我有以下代码。

//Create a view to place repeated arrow in.
UIView *rootView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];

//Add Repeated Arrows to the top of the view using a color pattern.
UIImage *arrowImage = [UIImage imageNamed:@"arrow-down"];
UIColor *repeatedArrowColor = [UIColor colorWithPatternImage:arrowImage];
CGRect repeatedArrowFrame = CGRectMake(0, 0, 320.0, [arrowImage size].height);
UIView *repeatedArrowView = [[UIView alloc] initWithFrame:repeatedArrowFrame];
[repeatedArrowView setBackgroundColor:repeatedArrowColor];

[rootView addSubview:repeatedArrowView];

正在使用的图像是带有箭头颜色#323232的png。我通过右键单击.app文件并选择显示包内容来验证这一点。

Image used to generate pattern.

然而,当模式出现在iOS模拟器屏幕上时,箭头的颜色为#262626或#252525。

Wrong colored arrows in the iOS simulator

有没有人遇到这个问题?如果是这样,你是如何解决的,或者你是否解决了这个问题?

1 个答案:

答案 0 :(得分:0)

总之,每个人都有这些问题。如果您在预览中打开该图像并使用pixie(开发工具),您将看到像素的值不同于文件中的值。该值是否与您在模拟器中看到的值不同?

你的png中是否嵌入了颜色配置文件?如果你有一个删除它可能会有所帮助(pngcrush将这样做作为一个选项)。如果没有,或者没有修复它,那么您可能需要首先使用以下内容将图像作为CGImageRef加载:

CGImageRef CGImageCreateWithPNGDataProvider (
   CGDataProviderRef source,
   const CGFloat decode[],
   bool shouldInterpolate,
   CGColorRenderingIntent intent
);

用颜色意图(第一个)和解码数组作为最后一个选项。

相关问题