繁体   English   中英

将导航栏文本颜色和状态栏图标更改为白色

[英]Change navigation bar text color and status bar icons to white

我已成功将导航栏的背景色设置为黑色。 在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;
}

有没有一种方法可以将导航栏标题和状态栏中的图标设置为白色?

对于导航栏:

navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: yourColor};

或者,使用外观

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

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

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

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

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM