UIViewController与背景图像

ghi*_*boz 6 iphone background-image uiviewcontroller ipad

如何将来自资源的图像作为背景图像插入到我的UIViewController中?提前致谢!

luv*_*ere 18

添加它UIViewController的视图,有点像这样:

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

   [self.view addSubview: imageView]; 

   [imageView release];

   [super viewDidLoad];
}
Run Code Online (Sandbox Code Playgroud)

  • 没有必要添加图像视图,这将使视图控制器加载缓慢.简单地说,在故事板中将视图的背景更改为任何颜色,然后在`viewDidLoad`中添加`[[self view] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]]];`it即使滚动,也会让它变得更好并且看起来很棒. (5认同)
  • 对于背景视图,您可能希望使用`[self.view insertSubview:imageView atIndex:0];`否则它将在您的其他xib之上. (4认同)

Tec*_*Zen 8

UIViewControllers没有背景图片.只有视图本身具有视觉属性.

UIView没有背景图片属性.要显示背景图像,通常只需将UIImageView显示在视图层次结构中,以便在所有其他视图后面以可视方式显示.这可以通过编程方式或在Interface Builder中完成.