Snail—UI学习之自定义导航栏NSNavigationController
2015-07-24 17:22
417 查看
首先新建一个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;
}
在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;
}
相关文章推荐
- ios UITableView代码
- EF6 CodeFirst+Repository+Ninject+MVC4+EasyUI实践(五)
- java.io.IOException: Tried to send an out-of-range integer as a 2-byte value
- c#通常什么地方遇到数据库为空 System.DBNull.Value 作者:admin
- Arcgis Server开发使用query报错
- Arduino硬件开发--红外遥控舵机
- 图解hdu5301Buildings
- iOS UILabel文本行间距
- CF 559B(Equivalent Strings-构造法)
- hdu 5301 Buildings
- 注意 ExecuteNonQuery() 返回值 问题
- jsoncpp-0.5,支持uint64
- iOS Human Interface Guidelines(原创翻译) 目录
- Building Accessibility Services
- UILabel长度自适应内部字符串NSString纪录
- Failed to instantiate the default view controller for UIMainStoryboardFile 'MainStoryboard'
- Snail—UI学习之导航视图控制器UINavigationController(系统)
- 【源代码】java.util.Stack & Queue
- 给UITextField设置图标
- UITableView 使用 selectRowAtIndexPath 不能默认选中cell的问题