設置導航欄背景圖片為一個空的image,這樣就透明了,一般情況下我們在
-(void)viewWillAppear:(BOOL)animated{
//設置導航欄為透明
}
-(void)viewWillDisappear:(BOOL)animated{
//還原導航欄的顏色
}
設置導航欄為透明的
設置導航欄背景圖片為一個空的image,這樣就透明了
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
去掉透明后導航欄下邊的黑邊
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
還原導航欄的顏色
把之前加上的image設置為nil
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:nil];
設置導航欄兩邊按鈕的顏色
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
隱藏返回按鈕 右邊的文字
[[UIBarButtonItem appearance]setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) forBarMetrics:UIBarMetricsDefault];
導航欄上的自定義標題
//自定義標題視圖
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0, 200, 44)];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.font = [UIFont boldSystemFontOfSize:17];
titleLabel.textColor = [UIColor whiteColor];
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.text = @"個人資料";
self.navigationItem.titleView = titleLabel;
導航欄的顏色
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
導航欄的透明度
不透明
self.navigationController.navigationBar.translucent = NO;
半透明
self.navigationController.navigationBar.translucent = YES;
導航欄的跳轉
返回到上個頁面
[self.navigationController popViewControllerAnimated:YES];
返回到第一個頁面
[self.navigationController popToRootViewControllerAnimated:YES];
返回到指定的頁面
NSArray *temArray = self.navigationController.viewControllers;
for(UIViewController *temVC in temArray){
if ([temVC isKindOfClass:[VillagersViewController class]]){
[self.navigationController popToViewController:temVC animated:YES];
}
}