【问题标题】:Change navigation bar text color and status bar icons to white将导航栏文本颜色和状态栏图标更改为白色
【发布时间】:2015-09-18 18:28:57
【问题描述】:

我已成功将导航栏的背景颜色设置为黑色。 在 AppDelegate.m 中:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    UINavigationBar *navigationBarAppearance = [UINavigationBar appearance];
    [navigationBarAppearance setBarTintColor:[UIColor blackColor]];
    [[UINavigationBar appearance] setTranslucent:NO];
    return YES;
}

有没有办法将导航栏标题和状态栏中的图标设置为白色?

【问题讨论】:

    标签: ios


    【解决方案1】:

    对于导航栏:

    navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: yourColor};
    

    或者,使用外观

    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: yourColor}];
    

    如果您希望整个应用程序中的状态栏为白色,请在 Info.plist 中将 View controller-based status bar appearance 设置为 NO。之后,在您的应用委托中执行以下操作

    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    [self.window setBackgroundColor:[UIColor whiteColor]];
    

    显然setStatusBarStyle: 在 iOS 9 中已被弃用,因此请改用preferredStatusBarStyle。为此,请将以下内容添加到您的每个视图控制器中

    - (UIStatusBarStyle)preferredStatusBarStyle
    {
        return UIStatusBarStyleLightContent;
    }
    

    【讨论】:

    • 我正在使用 [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: whiteColor}];,但我在 whiteColor 上收到 Use of undeclared identifier 错误
    • 改用[UIColor whiteColor]
    • 它适用于导航栏。它也可以使用状态栏中的图标,但它表示 setStatusBarStyle 已弃用
    • 它正在工作。我想问你另一个问题。我可以更改 blackColor 并使用 #00cc00 格式吗?
    • 我个人不太了解在 iOS 中使用十六进制值,但this answer 似乎对您有所帮助。
    猜你喜欢
    • 1970-01-01
    • 2017-08-16
    • 1970-01-01
    • 1970-01-01
    • 2015-03-05
    • 1970-01-01
    • 1970-01-01
    • 2021-06-18
    相关资源
    最近更新 更多