【问题标题】:colorWithPatternImage creates black grids in iphone 4colorWithPatternImage 在 iphone 4 中创建黑色网格
【发布时间】:2011-10-02 05:05:24
【问题描述】:

我有

UIView *topPart = [[UIView alloc] initWithFrame:CGRectMake(9, 0, 302, 318)];
topPart.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"pattern.png"]];
[someScroller addSubview:topPart];
[topPart release];

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

有人遇到不同的问题,但可能是相同的解决方案 colorWithPatternImage with iPhone 4 Retina Display (image@2x.png)

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

谢谢

【问题讨论】:

标签: uicolor iphone-4


【解决方案1】:

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

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

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

希望对你有帮助:)

【讨论】:

    【解决方案2】:

    我通过结合这 2 个帖子的答案来解决这个问题 https://devforums.apple.com/message/259150#259150

    How can I use CGContextDrawTiledImage to tile an image?

    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;
    }
    

    希望这对其他人有所帮助

    【讨论】:

      猜你喜欢
      • 2011-08-22
      • 1970-01-01
      • 2012-03-25
      • 2013-03-30
      • 2014-01-30
      • 1970-01-01
      • 1970-01-01
      • 2013-07-21
      • 1970-01-01
      相关资源
      最近更新 更多