2011-04-07 122 views
0

我想为UITableViewController设置背景图像。我已经得到了下面的代码,它可以将背景设置得很好,但图像本身被拉伸到通常尺寸的两倍左右。UITableViewController背景图像拉伸

[[self view] setAutoresizesSubviews:NO]; 

UIView *backgroundView = [[UIView alloc] initWithFrame:self.view.frame]; 
backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Default.png"]]; 

self.tableView.backgroundView = backgroundView; 
self.tableView.backgroundColor = [UIColor clearColor]; 

[backgroundView release]; 

图片是只有640x960像素。

我试过手动设置backgroundView的框架,但它不会改变背景图像的大小。

任何人都可以解释我要去哪里错了吗?

非常感谢。

回答

5

在我的expirience,你应该因为它会导致一些问题,选择合适的图像视网膜/低分辨率设备避免使用

[UIColor colorWithPatternImage: ... ];

尝试更多的东西是这样的:

UIImageView* bgView = [[[UIImageView alloc] initWithImage: 
[UIImage imageNamed:@"Default.png"]] autorelease]; 

[tableView.backgroundView addSubview:bgView]; 

另外,还要确保你有两个PNG文件:

+0

这工作很好! UIImageView管理完美地检测图像尺寸。并感谢关于这两个图像的提示:) – 2011-04-07 22:48:08