我是 Cocca 和 IOS 开发的新手,发现自己处于以下情况。
我有一张 1024x1024 的背景图片,我想在所有 View 中显示它。我已将以下代码放在应用程序委托(delegate)中的应用程序 didFinishLaunchingWithOptions 中,它可以正确加载并在所有 View 下可见。
我遇到的问题是我似乎无法将背景 UIView 居中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Setup background image for all views
UIView *backgroundView = [[UIView alloc] initWithFrame: window.frame];
backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background-image.png"]];
[window addSubview : backgroundView];
[backgroundView release];
// Override point for customization after application launch.
[window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
return YES;
}
我已经设法将背景 UIView 移动到不同的位置,但不是居中。
我会为此提供任何帮助。
提前致谢马特
尝试用...替换您的代码
UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background-image.png"]];
backgroundView.frame = window.frame;
[window addSubview:backgroundView];
[backgroundView release];
...如果您的 background-image.png 不适合,请尝试使用 backgroundView
của autoresizingMask
Và contentMode
整个窗口。
Tôi là một lập trình viên xuất sắc, rất giỏi!