導航控制器使用了導航堆棧。根視圖控制器(Settings)在堆棧最底層,以此類推。能夠理解爲一本書,一頁一頁的。這樣就控制了 試圖控制器php
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:spa
包含左右UIBarButtonItem,也就是左右兩個按鈕,下面添加左面按鈕:code
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(clickLeftButton)]; //初始化並非initWithBarButt....一種,聰明的你確定知道comand點進去了。有initWithTitle。。。等等,這個能夠改變按鈕文字 self.navigationItem.leftBarButtonItem = leftButton;
固然左邊的默認顯示的。右面的就不在這裏添加了吧orm
下面是按鈕樣式,自行參考get
toolBar:string
//顯示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];
自定義按鈕it
//把自定義的按鈕mybutton 添加到 UIBarButtonItem barButton = [[UIBarButtonItem alloc] initWithCustomView:mybutton];
// 讓iOS7 導航控制器不透明io
self.navigationController.navigationBar.translucent = NO; self.edgesForExtendedLayout = UIRectEdgeNone;
//隱藏導航欄table
[[self navigationController] setNavigationBarHidden:YES animated:YES];