关于UINavigationController的一些技巧
阅读原文时间:2023年07月14日阅读:1

未自定义任何东西的导航条效果如下:

1、自定义了 leftBarButtonItem 之后,左滑返回手势失效了,解决办法:

self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;

2、去掉  back

// 让默认返回“back”向上偏移 64  
\[\[UIBarButtonItem appearance\] setBackButtonTitlePositionAdjustment:UIOffsetMake(.f, -.f)  
                                                     forBarMetrics:UIBarMetricsDefault\];

3、修改 "<back"颜色

// 导航条文字和默认箭头颜色  
\[\[UINavigationBar appearance\] setTintColor:\[UIColor redColor\]\];

4、修改导航条背景颜色

// 导航条背景颜色  
\[\[UINavigationBar appearance\] setBarTintColor:\[UIColor lightGrayColor\]\];

5、滑动时隐藏、下拉是出现到导航。该属性为iOS8之后出现

// 滑动时隐藏、下拉是出现到导航。该属性为iOS8之后出现  
self.navigationController.hidesBarsOnSwipe = YES;

6、修改 navigationBar 为透明色

   [self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;

7、起初statusbar是lightcontent的,但是使用 UIImagePickerController 导致statusbar的样式变成黑色,解决办法

// 起初statusbar是lightcontent的,但是使用 UIImagePickerController 导致statusbar的样式变成黑色,解决办法:

  • (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
    {
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    }

尊重作者劳动成果,转载请注明: 【kingdev】

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章