标签:
首先新建一个RootViewController 再建一个FirstViewController
在RootViewController.m中写入
#import "WJJRootViewController.h" #import "WJJFirstViewController.h" @interface WJJRootViewController () @end @implementation WJJRootViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor grayColor]; [self createMyNavigationBar]; } - (void)createMyNavigationBar{ //手机最上面的状态栏20像素 系统导航栏高度为44 所以一共64像素 UIView * navigationBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 64)]; navigationBar.backgroundColor = [UIColor redColor]; [self.view addSubview:navigationBar]; //定义一个按钮 UIButton * pushButton = [UIButton buttonWithType:UIButtonTypeSystem]; pushButton.frame = CGRectMake(self.view.frame.size.width- 10 - 50, 27, 50, 30); [pushButton setTitle:@"下一页" forState:UIControlStateNormal]; [pushButton addTarget:self action:@selector(nextPage) forControlEvents:UIControlEventTouchUpInside]; //把按钮放在自定义的导航栏上 [navigationBar addSubview:pushButton]; } - (void)nextPage{ WJJFirstViewController * first = [[WJJFirstViewController alloc] init]; [self.navigationController pushViewController:first animated:YES]; } - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; //因为后面的界面有可能使用系统导航栏 会把此属性设置为NO不隐藏 所以有必要在这设置一下 以防万一 self.navigationController.navigationBarHidden = YES; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor blackColor]; } - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; //设置系统导航栏不隐藏 使用系统导航栏 self.navigationController.navigationBarHidden = NO; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
Snail—UI学习之自定义导航栏NSNavigationController
标签:
原文地址:http://blog.csdn.net/qq1791422018/article/details/47044283