2010-06-07 59 views

回答

18

它添加UIViewController的觀點,有點像這樣的:你,我已經看了很多帖子關於背景圖像和試過各種代碼,沒有工作

- (void) viewDidLoad 
{ 
    UIImage *background = [UIImage imageNamed: @"background.png"];  
    UIImageView *imageView = [[UIImageView alloc] initWithImage: background]; 

    [self.view addSubview: imageView]; 

    [imageView release]; 

    [super viewDidLoad]; 
} 
+0

我在頂部看到約10px的邊距。有什麼我失蹤了嗎? – 2011-04-29 03:19:16

+0

@vishalashah在將其添加爲子視圖之前,嘗試將imageview的框架設置爲viewcontroller視圖的框架。 – luvieere 2011-04-29 05:31:05

+4

對於背景視圖,您可能想要使用'[self.view insertSubview:imageView atIndex:0];否則它會在其他xib的東西之上。 – Intentss 2012-11-22 19:16:43

8

UIViewControllers沒有背景圖像。只有視圖本身具有視覺屬性。

UIView沒有背景圖像屬性。要顯示背景圖像,通常只需將UIImageView顯示在視圖層次結構中,以便在所有其他視圖之後以可視方式顯示。這可以通過編程或在Interface Builder中完成。

+0

謝謝,這似乎與故事板這是完成的最佳方式。謝謝。 – Ergin 2014-09-17 20:54:39