1

我创建了一个名为 img 的组,并在其中放置了一张我想作为背景出现的图像。

但相反,背景变成了全黑。

这是我用于此的代码。我把代码放在viewDidAppear方法中

self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"img/building.png"]];

有没有想过我可能做错了什么?

4

2 回答 2

1

我假设您正在从应用程序包中加载图像?如果是这种情况,则 UIImage 未正确创建。

尝试:

UIImage *image = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"building" ofType:@"png"]];
self.view.backgroundColor = [UIColor colorWithPatternImage:image];
于 2012-08-07T15:39:35.310 回答
1

[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"building.png"]];改为使用

于 2012-08-07T15:32:17.247 回答