2011-06-06 34 views
0

我正在使我的應用程序具有通用性,但是我在調​​整背景圖像大小時遇到​​了一個小問題。這是我的代碼在通用應用程序中調整大小視圖

UIImageView *myImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"dubstep2.jpg"]]; 
[self.view addSubview:myImage]; 
UIScreen *screen = [UIScreen mainScreen]; 
[myImage setFrame:[screen applicationFrame]]; 
[myImage release]; 

我把它放在viewDidLoad中。圖像調整大小,但它不會「正確」調整大小,因爲我有一個tabBar。所以一部分視圖是隱藏的,它在頂部留下一個小小的空白。調整大小時,我需要這種觀點。我曾嘗試在界面構建器中添加圖像視圖並將圖像分配給該圖像,然後在IB中對其進行調整,但仍不會移位。

回答

0

關於您是使用UITabBar對象還是使用UITabBarController並不完全清楚。這很可能是UITabBarController,所以我認爲所提供的代碼來自您的一個視圖控制器。在這種情況下,你必須這樣做 -

UIImageView * myImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"dubstep2.jpg"]]; 
myImage.frame = self.view.bounds; 
myImage.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; // This will make sure that `myImage` is latched onto its parent view's edges. 

[self.view addSubview:myImage]; 
[myImage release]; 
+0

是它的UITabBarController。謝謝 – user772489 2011-06-20 05:34:44

相關問題