Uicolor colorWithPatternImage在iphone 4中创建黑色网格

Uicolor colorWithPatternImage在iphone 4中创建黑色网格,uicolor,iphone-4,Uicolor,Iphone 4,我有 当我使用3gs或iphone模拟器时,我可以很好地看到模式,但当我在实际的iPhone4上测试时,我看到了模式图像,但每个模式之间都有黑线分隔,所以看起来像一个网格。我检查了图案图像,没有黑色边框或任何东西 有人有不同的问题,但可能是相同的解决方案 但是他们建议使用-(void)drawRect:method,唯一的问题是我不知道怎么做 谢谢我把这两篇文章的答案结合在一起,找到了答案 希望这对其他人有所帮助我也遇到了同样的问题,发现这是因为我的png是灰度的(不是RGB) 要检查是否

我有

当我使用3gs或iphone模拟器时,我可以很好地看到模式,但当我在实际的iPhone4上测试时,我看到了模式图像,但每个模式之间都有黑线分隔,所以看起来像一个网格。我检查了图案图像,没有黑色边框或任何东西

有人有不同的问题,但可能是相同的解决方案

但是他们建议使用-(void)drawRect:method,唯一的问题是我不知道怎么做


谢谢

我把这两篇文章的答案结合在一起,找到了答案


希望这对其他人有所帮助

我也遇到了同样的问题,发现这是因为我的png是灰度的(不是RGB)

要检查是否是这种情况,只需在Xcode中选择图像,显示实用工具侧栏(右侧显示的侧栏)并查看颜色空间

要解决此问题,您可以使用您喜爱的图像编辑器,但对于photoshop,请执行以下操作: 打开灰度图像 选择全部并复制 创建一个新文档(但这次请确保颜色空间为RGB) 粘贴

希望有帮助:)

可能重复:
UIView *topPart = [[UIView alloc] initWithFrame:CGRectMake(9, 0, 302, 318)];
topPart.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"pattern.png"]];
[someScroller addSubview:topPart];
[topPart release];
UIImage *thePattern= [self GetFineTiles:[UIImage imageNamed:@"Feedbackpattern.png"]];
theView.backgroundColor = [UIColor colorWithPatternImage:thePattern];

-(UIImage*)GetFineTiles:(UIImage*)badImage{
    UIGraphicsBeginImageContext(badImage.size);
    CGContextRef imageContext = UIGraphicsGetCurrentContext();
    CGContextDrawTiledImage(imageContext, (CGRect){CGPointZero,badImage.size}, badImage.CGImage);
    UIImage *goodPattern = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return goodPattern;
}