免费开源的iOS开发学习平台

UINavigationController介绍:6-barTintColor与tintColor

barTintColor属性

barTintColor属性用于设置导航栏背景颜色, 通过修改该属性,可以设置导航栏的整体背景颜色。值得注意的是,虽然UINavigationBar继承自UIView,但是设置导航栏的背景颜色并不是使用backgroundColor属性,而是barTintColor属性

@property(nullable, nonatomic,strong) UIColor *barTintColor ; 

下方的示例代码中,对创建的导航栏背景颜色进行了设置。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  
    UIViewController *navRootVC = [[UIViewController alloc] init];
    navRootVC.view.backgroundColor = [UIColor whiteColor];
    
    UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:navRootVC];
    
    navVC.navigationBar.barTintColor = [UIColor greenColor];

    navRootVC.title = @"99iOS.com";
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.rootViewController = navVC;
    [self.window makeKeyAndVisible];
    
    return YES;
}

tintColor

tintColor属性用于设置导航栏图标被渲染的颜色。如下图所示,通过设置tintColor的值可以修改图片被渲染显示在屏幕上显示的颜色。

@property(null_resettable, nonatomic,strong) UIColor *tintColor;

示例代码

https://github.com/99ios/9.2.6