1.設(shè)置nav圖片
//設(shè)置圖片
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav_bg"]forBarMetrics:UIBarMetricsDefault];
//去除導(dǎo)航欄下面的黑線
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
2.設(shè)置透明導(dǎo)航欄
要遵循UINavigationControllerDelegate,UIGestureRecognizerDelegate兩個代理。
設(shè)置代理
self.navigationController.delegate = self;
self.navigationController.interactivePopGestureRecognizer.delegate = self;
self.edgesForExtendedLayout = UIRectEdgeNone;
代理方法:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animate{
if([viewController isKindOfClass:[self class]]){
[navigationController setNavigationBarHidden:YES animated:YES];
}
else{
[navigationController setNavigationBarHidden:NO animated:YES];
}
}
以上,就可以設(shè)置透明導(dǎo)航欄了。
3.在公共父類控制器中設(shè)置navtitle
首先在父類控制器的.h文件中聲明類型為NSString的title
@property(nonatomic ,copy)NSString *navTitle;
然后是設(shè)置title代碼在.m文件中
#pragma mark -- 設(shè)置title
- (void)setNavTitle:(NSString *)navTitle {
_navTitle = navTitle;
UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
UILabel *titleLabel = [UILabel new];
titleLabel.frame = titleView.bounds;
titleLabel.font = [UIFont systemFontOfSize:18.f];
titleLabel.text = navTitle;
titleLabel.textColor = RGB(51,51,51);
titleLabel.textAlignment = NSTextAlignmentCenter;
[titleView addSubview:titleLabel];
self.navigationItem.titleView = titleView;
}