首先新建一个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
然后 在firstViewController.m 中写入
- (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; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-11-08 20:50:02