2015-08-01

iOS 应用修改状态栏和导航栏颜色

Views: 18052 | Add Comments

修改状态栏

在 Target::Info 栏里, 找到 Custom iOS Target Properties, 加入一项配置项:

Key: View controller-based status bar appearance
Type: Boolean
Value: NO

这样, 就可以修改状态栏的字体颜色了, 否则没法改. 然后修改 AppDelegate:

- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)opts {
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}

修改导航栏背景和字体颜色

- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)opts {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    UINavigationController *nav = [[UINavigationController alloc] init];
    nav.navigationBar.tintColor = [UIColor whiteColor];
    nav.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};
    nav.navigationBar.barTintColor = [UIColor blueColor];
    nav.navigationBar.translucent = NO;

    self.window.rootViewController = nav;
    [self.window makeKeyAndVisible];

    return YES;
}
  • tintColor: 导航栏的按钮(如返回)颜色
  • titleTextAttributes: 标题颜色
  • barTintColor: 背景颜色
  • translucent: 是否透明

Related posts:

  1. 动态规划算法的发现
  2. 把Firefox的播放背景音乐功能去掉
  3. Cocoa 应用检测 ESC 按键
  4. AVFoundation音频格式在录音过程中变动
  5. NSView NSImage NSData转换
Posted by ideawu at 2015-08-01 15:50:17 Tags:

Leave a Comment