UINavigationController

设置导航栏样色

#-------设置导航栏不半透明,从导航栏下面开始算起点 重要 控制器都要这么设置
self.navigationController.navigationBar.translucent = NO;

#-------设置中部文字属性
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
#-------设置返回文字颜色
[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
#-------修改NavigationBar背景颜色为orangeColor
[self.navigationController.navigationBar setBarTintColor:[UIColor orangeColor]];
#-------修改NavigationBar的背景图片
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"Bar_bg"] forBarMetrics:UIBarMetricsDefault];
#-------设置为没有毛玻璃效果,view Controller背景为lightGray
[self.navigationController.navigationBar setTranslucent:NO];
#-------去除导航栏底部线,在iOS 10 这样写会有问题,当导航栏颜色和下面接壤的颜色为同个颜色,系统自动出现黑色线,用下面2句代码比较妥
[[UINavigationBar appearance]  setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
#-------设置导航栏item 字体大小
 [self.navigationItem.rightBarButtonItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17],NSFontAttributeName, nil] forState:UIControlStateNormal];


设置 navigationBar 的 setBackgroundImage 控制器会向下偏移 64
https://www.jianshu.com/p/9a413405b253

UINavigationBar样式
https://www.jianshu.com/p/f7f48ccab1d8
iOS状态栏的相关设置
https://www.jianshu.com/p/46027d842db2
https://www.jianshu.com/p/1dd3a2aec890
自定义返回按钮
https://blog.csdn.net/xuzenghuifeng/article/details/78875611
https://blog.csdn.net/Mango_ios/article/details/70155599
https://blog.csdn.net/qq_31810357/article/details/78364336
去掉导航栏UINavigationBar最下面的黑线
https://www.jianshu.com/p/202afecc7a9c
导航栏按钮位置偏移
https://github.com/spicyShrimp/UINavigation-SXFixSpace

第三方
https://github.com/rickytan/RTRootNavigationController
https://github.com/telly/TLYShyNavBar
在UIViewController中设置title与navigationItem.title的区别
https://www.jianshu.com/p/85e513aed038

设置状态栏颜色为白色

http://blog.csdn.net/deft_mkjing/article/details/51705021
设置导航栏阴影线的尺寸和颜色
https://www.jianshu.com/p/ff1e2ffaa152

##在 SCRootViewController,SCRootNavigationController 添加
## info.plist文件中是否有View controller-based status bar appearance 这个属性,如果有看是否为YES

-(UIStatusBarStyle)preferredStatusBarStyle
{
    
    return UIStatusBarStyleLightContent;
}
//或
self.navigationController.navigationBar.barStyle=UIBarStyleDefault; //黑色
UINavigationController_第1张图片
Paste_Image.png

文字按钮

UIBarButtonItem *editItem = [[UIBarButtonItem alloc] initWithTitle:@"点击" style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
    self.navigationItem.rightBarButtonItem = editItem;

- (void)backAction
{
}

图片按钮

     UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightButton setFrame:CGRectMake(0.0, 0.0, 44.0, 44.0)];
    [rightButton addTarget:self action:@selector(Action) forControlEvents:UIControlEventTouchUpInside];
    rightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [rightButton setImage:[UIImage imageNamed:@"xx"] forState:UIControlStateNormal];
    //rightButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
    self.navigationItem.rightBarButtonItem = rightItem;

- (void)Action{
    
}

隐藏导航栏

### 状态栏颜色可能变为白色,看不到
- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    [super viewWillAppear:animated];
    
}
- (void)viewWillDisappear:(BOOL)animated
{
    
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    [super viewWillDisappear:animated];
}

退回指定页面

 for (UIViewController *vc in self.navigationController.viewControllers) {
        //返回到购物车界面
        if ([vc isKindOfClass:[MJShoppingCarVC class]]) {
            [self.navigationController popToViewController:vc animated:YES];
        }
     
    }

模态视图推送

    [self presentViewController:VC animated:YES completion:^{}];

    [self dismissViewControllerAnimated:YES completion:^{}];

###导航栏包裹
 YZGRootNavigationController *nav = [[YZGRootNavigationController alloc] initWithRootViewController:[KViewController new]];

设置CGRectZero从导航栏下开始计算

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = RGB(235, 235, 241);
    
     //设置CGRectZero从导航栏下开始计算
    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)])
    {
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
    
}

你可能感兴趣的:(UINavigationController)