colorWithPatternImage在iPhone 4中创建黑色网格 [英] colorWithPatternImage creates black grids in iphone 4
问题描述
我有
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上进行测试时,我看到了图案图像,但是每个图案之间都有黑线分隔,因此看起来像是网格.我检查了图案图像,没有黑色边框或其他任何东西.
and I can see the pattern fine when I use a 3gs or the iphone simulator, but when I tested on an actual iPhone 4, I see the pattern images but there are black lines separating each pattern so it looks like a grid. I checked the pattern image and there is no black border or anything .
有人遇到了不同的问题,但是可能是相同的解决方案 带有iPhone 4视网膜显示屏(color@2x.png)的colorWithPatternImage
There was someone with a different problem but it may be the same solution colorWithPatternImage with iPhone 4 Retina Display (image@2x.png)
但是他们建议使用-(void)drawRect:方法,唯一的问题是我不知道该怎么做.
but they suggested using the -(void)drawRect: method, only problem is i have no idea how to do that.
谢谢
推荐答案
我通过结合这2个帖子的答案来解决问题 https://devforums.apple.com/message/259150#259150
I figured it out by combining the answers from these 2 posts https://devforums.apple.com/message/259150#259150
如何使用CGContextDrawTiledImage来平铺图像?/a>
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;
}
希望这对其他人有帮助
这篇关于colorWithPatternImage在iPhone 4中创建黑色网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!