首先你需要设置导航栏,假设你的第一个屏幕是SpalshViewController,你需要将启动屏幕设置为导航栏的根视图控制器,然后将导航栏设置为根视图控制器:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
SplashScreenVC *obj =[CustomUtility getViewController:@"SplashScreenVC"];
self.navigationController =[[UINavigationController alloc] initWithRootViewController:obj];
self.window.rootViewController =self.navigationController;
在didFinishLaunchingWithOptions
现在来自定义导航栏设置和您需要设置的外观:
self.navigationController.navigationBar.translucent = NO;
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"top_bg2.png"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor],NSFontAttributeName:[UIFont fontWithName:@"Lato-Regular" size:18]}];
现在为导航栏设置自定义栏按钮,您需要创建 barbutton 项目,例如:
UIBarButtonItem *leftbtn;
UIBarButtonItem *rightbtn;
[self.navigationController.navigationItem setLeftBarButtonItem:leftbtn];
[self.navigationController.navigationItem setRightBarButtonItem:rightbtn];
自定义barbuttonItems根据你的需要
如果你想在导航栏上设置多个按钮,你可以添加如下:
UIBarButtonItem *leftbtn1;
UIBarButtonItem *leftbtn2;
UIBarButtonItem *rightbtn1;
UIBarButtonItem *rightbtn2;
[self.navigationController.navigationItem setLeftBarButtonItems:@[leftbtn1,leftbtn2]];
[self.navigationController.navigationItem setRightBarButtonItems:@[rightbtn1,rightbtn2]];
希望对你有帮助