- 实现步骤:
- 获取导航栏对象。
- 设置导航栏的背景颜色为蓝色。
- 设置导航栏标题的颜色为白色。
- 关键代码示例:
在
UIViewController
的viewDidLoad
方法中:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 获取导航栏
UINavigationBar *navigationBar = self.navigationController.navigationBar;
// 设置导航栏背景颜色为蓝色
navigationBar.barTintColor = [UIColor blueColor];
// 设置导航栏标题颜色为白色
NSDictionary *attributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};
navigationBar.titleTextAttributes = attributes;
}
@end