cuốn sách gpt4 ai đã làm

xcode - Trung tâm UIView

In lại Tác giả: Walker 123 更新时间:2023-11-28 17:47:11 30 4
mua khóa gpt4 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 移动到不同的位置,但不是居中。

我会为此提供任何帮助。

提前致谢马特

câu trả lời hay nhất

尝试用...替换您的代码

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 autoresizingMaskcontentMode整个窗口。

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

30 4 0
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress