基礎(chǔ)設(shè)置
- 隱藏導(dǎo)航欄
self.navigationController.navigationBarHidden = YES;
- 去掉透明效果
[self.navigationController.navigationBar setTranslucent:NO];
提示:
NO:無(wú)透明效果 + 會(huì)向下偏移64
YES:有透明效果 + 不會(huì)向下偏移64
中間標(biāo)題
- 修改中間標(biāo)題的文字顏色
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor colorWithRed:1.0 green:0.4118 blue:0.4392 alpha:1.0] forKey:UITextAttributeTextColor];
- 單獨(dú)設(shè)置nav標(biāo)題
NSDictionary *navTitleArr = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:20],UITextAttributeFont,[UIColor redColor],UITextAttributeTextColor ,[NSValue valueWithCGSize:CGSizeMake(2.0, 2.0)] , UITextAttributeTextShadowOffset ,[UIColor whiteColor] ,UITextAttributeTextShadowColor ,nil];
[self.navigationController.navigationBar setTitleTextAttributes:navTitleArr];
左右item設(shè)置
- 改變返回按鈕的顏色
self.navigationController.navigationBar.tintColor = [UIColor redColor];
- 隱藏返回按鈕
[self.navigationItem setHidesBackButton:YES];
- 去掉返回按鈕的文字(如果添加了左按鈕,可以自動(dòng)去掉返回按鈕的文字)
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];
- 添加右按鈕
UIBarButtonItem *leftBtnItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"111"] style:UIBarButtonItemStyleDone target:self action:@selector(share:)];
[self.navigationItem setRightBarButtonItem:leftBtnItem];
- 可以把左按鈕 - 做成返回按鈕
UIBarButtonItem *leftBtnItem= [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"nav_leftbtn"] style:UIBarButtonItemStyleDone target:self action:@selector(goBackAction)];
leftBtnItem.imageInsets = UIEdgeInsetsMake(0, -10, 0, 0);
[self.navigationItem setLeftBarButtonItem:leftBtnItem];
- 修改返回按鈕背景
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(0, 0, 25, 25);
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
[btn setImage:[UIImage imageNamed:@"nav_leftbtn"] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(goBackAction:) forControlEvents:UIControlEventTouchUpInside];
btn.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 10);
[self.navigationItem setLeftBarButtonItem:leftItem];
Nav背景
- 修改Nav背景
(1)半透明
self.navigationController.navigationBar.backgroundColor = [UIColor colorWithRed:0.98f green:0.98f blue:0.98f alpha:1.00f];
(2)不帶半透明的效果
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
- 更改nav背景圖片
UIImage *image = [UIImage imageNamed:@"333"];
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
- 去掉nav 那個(gè)黑色的分割線
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
其他
- 添加系統(tǒng)默認(rèn)的nav手勢(shì)返回
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
self.navigationController.interactivePopGestureRecognizer.delegate=(id)self;