一暂吉、設(shè)置導(dǎo)航欄背景全透明
-(void)viewWillAppear:(BOOL)animated{
? ? //設(shè)置導(dǎo)航欄背景圖片為一個(gè)空的image弥搞,這樣就透明了
? ? [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
? ? //去掉透明后導(dǎo)航欄下邊的黑邊
? ? [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
}
- (void)viewWillDisappear:(BOOL)animated{
? ? //? ? 如果不想讓其他頁(yè)面的導(dǎo)航欄變?yōu)橥该?需要重置
? ? [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
? ? [self.navigationController.navigationBar setShadowImage:nil];
}
二埂软、iOS中設(shè)置導(dǎo)航欄標(biāo)題的字體顏色和大小
[self.navigationController.navigationBar setTitleTextAttributes:
@{NSFontAttributeName:[UIFont systemFontOfSize:19],
NSForegroundColorAttributeName:[UIColor redColor]}];
三么介、不同條件界面的跳轉(zhuǎn)
1拧咳、導(dǎo)航控制器的push和pop
導(dǎo)航控制器的跳轉(zhuǎn)方式诞挨,首先我們?cè)赼ppDelegate中設(shè)置其中一個(gè)viewController為導(dǎo)航控制器的根視圖控制器底靠,再把這個(gè)導(dǎo)航控制器設(shè)置為window的根視圖控制器
AppDelegate.m//
//生成一個(gè)viewController對(duì)象
ViewController *rootVC = [[ViewController alloc]init];
//把這個(gè)對(duì)象設(shè)置為導(dǎo)航控制器的根視圖
UINavigationController *naVC = [[UINavigationController alloc]initWithRootViewController:rootVC];
//將這個(gè)導(dǎo)航控制器設(shè)置為整個(gè)工程的window的根視圖控制器
self.window.rootViewController = naVC;
然后我們就可以在這個(gè)viewController里跳轉(zhuǎn)到其他界面了:[self.navigationController pushViewController:secondVC animated:YES];
然后要返回的話在那個(gè)界面安排一個(gè)回調(diào)方法害晦,代碼可以寫(xiě):[self.navigationController popViewControllerAnimated:YES];這樣就直接返回跳轉(zhuǎn)之前的界面了
2、模態(tài)
模態(tài)比較簡(jiǎn)單暑中,從這個(gè)界面跳到下個(gè)界面時(shí)我們直接用以下代碼券盅,直接讓它present出來(lái)就可以了锋八。
[self presentViewController:showVC animated:YES completion:nil];
從新顯示的界面回來(lái)的時(shí)候用以下代碼枕面,把它自己dismiss掉就可以了
[self dismissViewControllerAnimated:YES completion:nil];
如果既想用模態(tài)的方式又想讓第二界面的導(dǎo)航欄存在静秆,那么在模態(tài)時(shí)把它添加進(jìn)導(dǎo)航控制器就行了。
//實(shí)例化一個(gè)第二界面對(duì)象
SecondViewController *SecondVC= [[SecondViewController alloc]init];
UINavigationController *naVC = [[UINavigationController alloc]initWithRootViewController: SecondVC];
[self.navigationController presentViewController:naVC animated:YES completion:nil];
3严衬、Storyboard的segues方式跳轉(zhuǎn)
此方法僅適用于Storyboard中各個(gè)頁(yè)面連線后的跳轉(zhuǎn)澄者,鼠標(biāo)點(diǎn)擊viewControlller,按住control鍵拖拽到另一個(gè)View頁(yè)面,在彈出的segue頁(yè)面中選擇跳轉(zhuǎn)模式即可粱挡,連線完之后選中連線赠幕,在Identifier填上對(duì)應(yīng)的標(biāo)示,然后再在需要跳轉(zhuǎn)的地方實(shí)現(xiàn)如下代碼即可:
[self performSegueWithIdentifier:@"test" sender:self];
四询筏、讓UIView中的Button點(diǎn)擊之后跳轉(zhuǎn)到另一個(gè)ViewController上去
如果使用導(dǎo)航
第一個(gè)按鈕方法:
[self.navigationController pushViewController:secondVC animated:YES];
第二個(gè)按鈕方法:
[self.navigationController popViewControllerAnimated:YES];
如果使用模態(tài)
第一個(gè)按鈕方法:
[self presentViewController:secondVC animated:YES completion:nil];
第二個(gè)按鈕方法:
[self dismissViewControllerAnimated:YES completion:nil];
返回
[self.navigationController popViewControllerAnimated:YES];