调整通用应用程序中的视图

时间:2011-06-06 21:37:39

标签: iphone ipad

我正在使我的应用程序具有通用性,但我在调整背景图像大小方面遇到了一个小问题。这是我的代码

 UIImageView *myImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"dubstep2.jpg"]];
[self.view addSubview:myImage];
UIScreen *screen = [UIScreen mainScreen];
[myImage setFrame:[screen applicationFrame]];
[myImage release];

我把它放在viewDidLoad中。图像调整大小,但它没有“正确”调整大小,因为我有一个tabBar。因此隐藏了一部分视图,并在顶部留下一个小间隙。我需要这个视图在调整大小时向上移动。我尝试在界面构建器中添加图像视图并将图像分配给它,然后在IB中调整它但它仍然没有移动。

1 个答案:

答案 0 :(得分:0)

您是否使用UITabBar对象或UITabBarController并不完全清楚。它最有可能是UITabBarController,所以我假设所提供的代码来自您的一个视图控制器。在这种情况下,你必须这样做 -

UIImageView * myImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"dubstep2.jpg"]];
myImage.frame = self.view.bounds;
myImage.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; // This will make sure that `myImage` is latched onto its parent view's edges.

[self.view addSubview:myImage];
[myImage release];