UINavigationController
- UINavigationController以棧的形式保存子控制器
- 棧的形式是先進后出,所以說我們一般只會看到棧頂的東西,剩下的東西都在棧頂下面,并且第一入棧的在棧的第最底部。
//使用push方法能將某個控制器壓入棧 -(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;
//使用pop方法可以移除控制器
-(UIViewController *)popViewControllerAnimated:(BOOL)animated;//回到根控制器(棧底控制器) -(NSArray *)popToRootViewControllerAnimated:(BOOL)animated;
設置導航條的內容
//設置導航條內容
self.navigationItem.title = @"根導航控制器";
//設置導航條左邊的按鈕
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"??" style:UIBarButtonItemStyleDone target:self action:@selector(leftBtn)];
//設置導航條的view(可自定義)
// self.navigationItem.titleView = [UIButton buttonWithType:UIButtonTypeInfoLight];
/*
UINavigationItem:控制導航條的內容
UIBarButtonItem:控制導航條上的按鈕內容
*/
//在ios7以后默認導航條上的按鈕會渲染成藍色,可以通過代碼告訴系統按鈕不要渲染圖片
UIImage *image = [UIImage imageNamed:@"navigationbar_friendsearch"];
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
// self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:image style:UIBarButtonItemStyleDone target:self action:@selector(righthBtn)];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"navigationbar_friendsearch"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"navigationbar_friendsearch_highlighted"] forState:UIControlStateHighlighted];
//導航條上的內容位置不能由開發者決定,開發者只能控制尺寸大小
button.frame = CGRectMake(500, 500, 30, 30);
//控件的尺寸由圖片決定
[button sizeToFit];
//設置導航條右邊的按鈕為自定義控件
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
}