【发布时间】:2011-02-28 18:45:12
【问题描述】:
如何将资源中的图像作为背景图像插入我的 UIViewController? 提前致谢!
【问题讨论】:
标签: iphone ipad uiviewcontroller background-image
如何将资源中的图像作为背景图像插入我的 UIViewController? 提前致谢!
【问题讨论】:
标签: iphone ipad uiviewcontroller background-image
UIViewControllers 没有背景图片。只有视图本身具有视觉属性。
UIView 没有背景图片属性。要显示背景图像,您通常只需将显示图像的 UIImageView 放在视图层次结构中,以便它在视觉上显示在所有其他视图的后面。这可以通过编程方式或在 Interface Builder 中完成。
【讨论】:
添加UIViewController的视图,有点像这样:
- (void) viewDidLoad
{
UIImage *background = [UIImage imageNamed: @"background.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage: background];
[self.view addSubview: imageView];
[imageView release];
[super viewDidLoad];
}
【讨论】:
[self.view insertSubview: imageView atIndex:0]; 否则它将在您的其他 xib 内容之上。
viewDidLoad 添加 [[self view] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]]]; 它会变得更好,即使滚动也会看起来很棒。