导航控制器使用了导航堆栈。根视图控制器(Settings)在堆栈最底层,以此类推。可以理解为一本书,一页一页的。这样就控制了 试图控制器
self.title = @"Settings"; // 改变标题
//其实这是一个区域 self.navigationItem.titleView =
这是一个View 那就好办了,我们可以添加button imageView UISegmentedControl选项卡
//视图控制器
ViewController1* vc = [[ViewController1 alloc] init];
//导航控制器
UINavigationController* nc = [[UINavigationController alloc] initWithRootViewController:vc];
self.window.rootViewController = nc;
ViewController2* vc2 = [[ViewController2 alloc] init];
//进入第二个页面
[self.navigationController pushViewController:vc2 animated:YES];
//返回上一个页面
[self.navigationController popViewControllerAnimated:YES];
//返回根页面
[self.navigationController popToRootViewControllerAnimated:YES];
//返回指定页面
[self.navigationController popToViewController:vcX animated:YES];
bar:
包含左右UIBarButtonItem,也就是左右两个按钮,下面添加左面按钮:
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(clickLeftButton)];
//初始化并不是initWithBarButt....一种,聪明的你肯定知道comand点进去了。有initWithTitle。。。等等,这个可以改变按钮文字
self.navigationItem.leftBarButtonItem = leftButton;
当然左边的默认显示的。右面的就不在这里添加了吧
下面是按钮样式,自行参考
toolBar:
//显示toolBar
[self.navigationController setToolbarHidden:NO];
//添加toolBar 把UIBarButtonItem 放到,,,,,///UIBarButtonSystemItemFlexibleSpace 空白按钮风格
[self setToolbarItems:[NSArray arrayWithObjects:,,,, nil];
///自己添加UIToolbar
初始化 用setItems 添加 UIBarButtonItem
UIToolbar* toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 416-84, 320, 44)];
toolBar.hidden = YES;
//toolBar.backgroundColor = [UIColor redColor];
[self.view addSubview:toolBar];
//批量给Toolbar添加按钮
NSMutableArray* array = [NSMutableArray array];
for (int i = 0; i < 7; i++) {
if (i%2==0) {
UIBarButtonItem* button = [[[UIBarButtonItem alloc] initWithTitle:[NSString stringWithFormat:@"%d",i] style:UIBarButtonItemStyleBordered target:self action:nil] autorelease];
[array addObject:button];
} else {
UIBarButtonItem* button = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil] autorelease];
//宽
//FixedSpace 固定空白
//FlexibleSpace 灵活分布空白
//button.width = 50;
[array addObject:button];
}
}
//如果是我们自己写的toolBar,用这个方法添加
[toolBar setItems:array animated:YES];
//如果是导航自带的toolBar,用这个方法添加
[self setToolbarItems:array];
自定义按钮
//把自定义的按钮mybutton 添加到 UIBarButtonItem
barButton = [[UIBarButtonItem alloc] initWithCustomView:mybutton];
// 让iOS7 导航控制器不透明
self.navigationController.navigationBar.translucent = NO;
self.edgesForExtendedLayout = UIRectEdgeNone;
//隐藏导航栏
[[self navigationController] setNavigationBarHidden:YES animated:YES];