tabBar,navigationBar,statuBar

  self.navigationBar.barTintColor = [UIColor blackColor];//改了,这个值影响整个bar的颜色,还会影响到statuBar的颜色

 self.navigationBar.tintColor = [UIColor whiteColor]; //改了,这个值影响Item的颜色(图片与文字等)

隐藏tabBar或者导航栏不成功,可能xib中没有勾选 Under top Bars Under Bottom Bars

present 的View修改statubar

1)打开项目的plist文件,设置View controller-based status bar appearance" 为 NO

2文件中的启动方法中设置UIApplication.shared.statusBarStyle = .lightContent

  1. // 设置导航条的色调 理解为"混合色"  
  2. self.navigationController.navigationBar.barTintColor = [UIColor blackColor];  
  3. // 导航栏默认是半透明状态  
  4. self.navigationController.navigationBar.backgroundColor = [UIColor blueColor];  
  5. // 左边返回按键颜色  
  6. // 导航栏标题颜色  
  7. [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];  
  8. self.navigationController.navigationBar.translucent = NO;  

//iOS 隐藏/去掉 导航栏返回按钮中的文字

[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)

 forBarMetrics:UIBarMetricsDefault];

// init with image

let item=UIBarButtonItem.init(image:UIImage.init(named: "goback") , style: .plain, target: self, action: #selector(goBack))

//修改返回键的颜色

self.navigationController.navigationBar.tintColor = [UIColor redColor];  

横向修改

UIButton *settingBtn = [SHUtils creatCustomButtonWithFrame:CGRectMake(0, 0, 60, 40) btnTitle:@"设置" btnFontSize:14 titleColor:[UIColor blackColor]];

[settingBtn addTarget:self action:@selector(clickTheSettingBtn) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *rightBar = [[UIBarButtonItem alloc]initWithCustomView:settingBtn];

UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]

                                   initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace

                                   target:nil action:nil];

negativeSpacer.width = -20;

self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:negativeSpacer,rightBar,nil];

纵向修改

navigationItem.leftBarButtonItem?.setBackgroundVerticalPositionAdjustment(-40, forBarMetrics: .Default);

(new UInavigationController的页面修改可以修改这条线中所有的),BackButton输入内容可以生成一个backitem,可以修改属性,要注意观察这条栈中可能会有多个backitem,那么就可能导致下面这个方法执行了还是没有隐藏成功。一般是xib中有多个backItem,代码也可以生成的,backItem貌似是可以传递给下一个UIViewController,如果是xib中有多个backItem就是把所有的backItem删除就可以了,或者在代码中在生成BackItem的这个UIViewControll中执行一次下面的代码,

        let item = UIBarButtonItem(title: "", style: .plain, target: self, action: nil)

        self.navigationItem.backBarButtonItem = item

如果修改第三方库或者Pod中的navigationBar,建议每次clear一下再run,会有缓存。

猜你喜欢

转载自blog.csdn.net/weixin_39872861/article/details/81011881
今日推荐