2011-04-07 149 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