簡體   English   中英

狀態欄背景色和半透明導航欄

[英]Status Bar Background Color with Translucent Navigation Bar

所以我對似乎是一個簡單的問題b之以鼻...

我正在嘗試使其在應用程序中的狀態欄具有背景色。 現在我遇到的問題是:

[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;

這意味着文本將為白色。 很好,但是問題出在我運行應用程序並使用它時。 我在選項卡欄控制器中嵌入了一個導航控制器(具有表視圖),以便當您向下滾動時,標題消失。 認為與Facbook,LinkedIn等類似的功能。

因此,現在發生的是,當我滾動狀態欄時,白色文本是半透明的...因此不可讀。

所以我想可以添加一個子視圖,如下所示:

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;

這意味着現在顏色仍然存在,但不正確,當我滾動時,您可以知道頂部有一個視圖,而不是導航欄“ Fading”中的文本進入頂部(如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];

希望對您有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM