gpt4 book ai didi

xcode - 居中 UIView

转载 作者:行者123 更新时间:2023-11-28 17:47:11 28 4
gpt4 key购买 nike

我是 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 不适合,请尝试使用 backgroundViewautoresizingMaskcontentMode整个窗口。

关于xcode - 居中 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5118417/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com