2011-03-09 75 views
1

我想讓我的RootView顯示在桌面上方的UIImage中。我怎麼能做到這一點?在RootView中的UIImageView

+0

你說的 「上面」 是什麼意思?你想把圖片放在表格視圖的開頭還是直接放在表格視圖的開頭? – hennes 2011-03-09 16:30:56

回答

0

您應該使用setBackgroundView方法。

一個小例子:

// my image 
UIImage *image = [[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"my_image" ofType:@"png"]] autorelease]; 

// an imageView to put the imagen on 
UIImageView *imageView = [[[UIImageView alloc] initWithImage:image] autorelease]; 

// we set the background of the table with the imageView  
[myTable setBackgroundView:imageView]; 
+0

autorelease沒有真正的需要,或者有嗎? backgroundView屬性由retain關鍵字定義,因此您可以在調用setBackgroundView之後保存釋放圖像和圖像視圖。 – hennes 2011-03-09 16:28:52

+0

準確地說,autorelease是沒有必要的。這只是我的許多習慣之一。對不起,如果它讓你迷惑了代碼的主要目的。 – 2011-03-09 16:33:31

相關問題