UINavigation的一些設(shè)置

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;
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 今天看了六哥(軟實力總裁劉興奇)的文章,講關(guān)于“走彎路,到底好不好”,看完以后有很多感悟,感覺六哥說得太有道理...
    永永_99閱讀 471評論 2 0
  • 今天無聊,上街逛了逛,遇見一奇皅人士,跟在后面一個勁叫著陌生的名字,還直嚷嚷"……等等,我就說一句話"額,好奇地轉(zhuǎn)...
    滄海一粟貝閱讀 717評論 0 1

友情鏈接更多精彩內(nèi)容