IMG_5901.JPG

tabbar及navigationbar的背景颜色问题

  • 原因:
    • 设置颜色方法在iOS15中失效
    • iOS13更新的API中新增了针对navigationBar,tabbar分别新增了新的属性专门管理这些滑动时候产生的颜色透明等等信息,由于我们应用兼容iOS10以上,对于导航栏的设置还没有使用UINavigationBarAppearance和UITabBarAppearance,但在更新的iOS15上失效,所以就变得设置失效 ```objectivec //设置navigationBar颜色 self.navigationController.navigationBar.barTintColor = [UIColor blueColor]; //设置tabBar背景色 self.tabBarController.tabBar.backgroundColor = [UIColor blueColor]; //设置tabBarItem字体颜色 NSMutableDictionary *normalAttributes = [NSMutableDictionary dictionary]; [normalAttributes setValue:[UIColor blueColor] forKey:NSForegroundColorAttributeName];

[self.tabBarItem setTitleTextAttributes:normalAttributes.copy forState:UIControlStateNormal]; [self.tabBarItem setTitleTextAttributes:normalAttributes.copy forState:UIControlStateSelected];

  1. - **解决办法--重新设置相关属性**
  2. - **tabBar & navigationbar**
  3. - **standardAppearance --- 常规状态**
  4. - **scrollEdgeAppearance --- 滚动状态**
  5. ```objectivec
  6. UITabBarAppearance *appearance = [[UITabBarAppearance alloc] init];
  7. //tabBaritem title选中状态颜色
  8. appearance.stackedLayoutAppearance.selected.titleTextAttributes = @{
  9. NSForegroundColorAttributeName:[UIColor blueColor],
  10. };
  11. //tabBaritem title未选中状态颜色
  12. appearance.stackedLayoutAppearance.normal.titleTextAttributes = @{
  13. NSForegroundColorAttributeName:[UIColor blueColor],
  14. };
  15. //tabBar背景颜色
  16. appearance.backgroundColor = [UIColor blackColor];
  17. self.tabBarItem.scrollEdgeAppearance = appearance;
  18. self.tabBarItem.standardAppearance = appearance;
  19. UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
  20. appearance.backgroundColor = [UIColor blackColor];
  21. self.navigationBar.standardAppearance = appearance;
  22. self.navigationBar.scrollEdgeAppearance = appearance;

tableView新属性

  • sectionHeaderTopPadding
  • iOS 15中,使用plain初始化时,tableView会给每一个section的顶部(header以上)再加上一个22像素的高度,形成一个section和section之间的间距 ```objectivec 为了配合以前的开发习惯,我们只需要在创建实例的时候进行对间距的设置即可

if (@available(iOS 15.0, *)) { tableView.sectionHeaderTopPadding = 0; }

或者全局设置

if (@available(iOS 15.0, *)) { [UITableView appearance].sectionHeaderTopPadding = 0; } ```