iOS自定義導航視圖

1.新建導航控制器類


image.png

2.自定義導航視圖部分樣式

    self.navigationBar.translucent = NO;
    self.navigationBar.barTintColor = [UIColor whiteColor];
    self.navigationBar.tintColor = UIColorHex(0x333333);

    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSFontAttributeName] = UIFontOfMedium(17);
    selectedAttrs[NSForegroundColorAttributeName] = UIColorHex(0x333333);
    [self.navigationBar setTitleTextAttributes:selectedAttrs];
    
    //設置導航欄Item字體
    UIBarButtonItem *barButtonItem = [UIBarButtonItem appearance];
    [barButtonItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:UIFontOfSemibold(15), NSFontAttributeName, nil] forState:UIControlStateNormal];
    [barButtonItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:UIFontOfSemibold(15), NSFontAttributeName, nil] forState:UIControlStateHighlighted];

3.自定義返回按鈕

//引入代理
self.interactivePopGestureRecognizer.delegate = self;
//代理方法
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    if (self.viewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
        UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"nav_back_black"] style:(UIBarButtonItemStyleDone) target:self action:@selector(backAction)];
        viewController.navigationItem.leftBarButtonItem = backItem;
    }
    [super pushViewController:viewController animated:animated];
}
//返回按鈕事件
- (void)backAction{
    [self popViewControllerAnimated:YES];
}
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容