2013-03-02 66 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

相关问题