gpt4 book ai didi

objective-c - 导航栏中清晰的背景图片

转载 作者:行者123 更新时间:2023-11-29 04:17:01 25 4
gpt4 key购买 nike

我的 View Controller 中的 viewWillAppear 中有以下代码。

- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

UIImage *image = [UIImage imageNamed:@"navbar.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[self.navigationController.navigationBar addSubview:imageView];
}

在添加新的导航栏图像(如上面的代码所示)之前,如何清除已有的导航栏背景图像?

此外,如何以最有效的方式为每个不同的 Controller 设置不同的导航栏背景图像?谢谢!

最佳答案

在 viewWillAppear 方法中,使用以下调用来设置导航栏的背景图像。

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar.png"] forBarMetrics:UIBarMetricsDefault];

如果您的应用也支持横向,您还需要为横向导航栏设置不同高度的背景图像:

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar_landscape.png"] forBarMetrics:UIBarMetricsLandscapePhone];

关于objective-c - 导航栏中清晰的背景图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13556423/

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