2013-03-02 83 views

回答

2

如果你想設置一個UIViewController的看法的backgroundColor,然後將你的代碼viewDidLoad,同樣適應:

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"map3.jpg"]]; 

一個UIViewController不直接擁有backgroundColor,但其觀點呢,像其他任何UIView一樣。

+0

感謝它的幫助! – JimmyYXA 2013-03-02 23:00:07

+1

儘管如此,除非實際上有圖案圖像(即平鋪和重複的圖像),否則應該使用「UIImageView」。 – 2013-03-02 23:10:46

+0

或者'self.view.layer.contents =(id)[UIImage imageNamed:@「map3.jpg」]。CGImage;' – fumoboy007 2013-03-02 23:40:53

1

一種方法是將該邏輯放入您的視圖控制器的-viewDidLoad方法中,用於UIImageView屬性。

+0

對不起,我寫的問題是錯誤的。我沒有imageview。我將圖像設置爲backgroundColor到我的視圖。我應該怎麼做呢? – JimmyYXA 2013-03-02 21:16:22

+0

然後在viewDidLoad方法中設置backgroundColor。它仍然是適當的地方。 – 2013-03-02 21:49:03

1

的UIView

如果你是在一個UIView類的地方在任何initWithFrame:initWithCoder:

initWithFrame當實例從代碼視圖被調用的代碼(例如UIView *myView = [[UIView alloc] initWithFrame:CGRectZero]; initWithCoder:被稱爲每當UIView的是加載from XIB file。

http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html

的UIViewController

如果在UIViewController一個共同的地方把它會在viewDidLoad

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html

相關問題