gpt4 book ai didi

ios - 带有半透明导航栏的状态栏背景颜色

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

所以我正在为一个看似简单的问题而烦恼......

我正在努力使我的应用程序中的状态栏具有背景色。现在我遇到的问题是:

[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;

这意味着文本将是白色的。这很好,但是当我运行应用程序并使用它时,问题就来了。我在标签栏 Controller 中嵌入了一个导航 Controller (带有一个表格 View ),这样当您向下滚动时,标题就会消失。想想与 Facbook、LinkedIn 等类似的功能。

现在发生的情况是当我滚动时状态栏是半透明的白色文本...因此不可读。

所以我想我可以添加一个 subview 如下:

UIView *addStatusBar = [[UIView alloc] init];
addStatusBar.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 20);
addStatusBar.backgroundColor = [UIColor orangeColor];
[self.window.rootViewController.view addSubview:addStatusBar];

这似乎可行,但颜色不对...所以我不得不关闭导航栏的半透明属性:

self.navigationController.navigationBar.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;
self.navigationController.navigationBar.translucent = NO;

这意味着现在颜色保持不变,但不正确,当我滚动时,您可以看出顶部有一个 View ,而不是导航栏中的文本“淡入淡出”到顶部(如 Facebook 和 LinkedIn)

我在这里错过了什么?有没有办法访问statusBar.backgroundColor??

感谢您的帮助。

一个

最佳答案

您不会在您的 plist 中找到“UIViewControllerBasedStatusBarAppearance”属性,但默认情况下它不存在。您必须通过单击 + 按钮自行添加,然后将其设置为“否”。

添加到 .plist 后,您必须转到 AppDelegate.m 文件并在 didFinishLaunchingWithOptions 方法中添加以下内容,添加以下代码行:

[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
UIView *addStatusBar = [[UIView alloc] init];
addStatusBar.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 20);
addStatusBar.backgroundColor = [UIColor orangeColor];

YourViewController *vc = (YourViewController *)[storyboard instantiateViewControllerWithIdentifier:@“YourViewController"];
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:vc];

self.window.rootViewController = tabBarControllerObj;
[self.window.rootViewController.view addSubview:addStatusBar];

希望对你有所帮助。

关于ios - 带有半透明导航栏的状态栏背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35094933/

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