iOS15-UITableView多了白条,导航栏和Tabbar变成白色和标题变黑处理--总结属性变化和原来基本的导航栏属性总结记录(看到就更新)
先看情况:

查资料发现iOS15 中
UITableView 新加了一个属性:sectionHeaderTopPadding,automaticDimension,就会导致顶部多出一条空白。- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//加这里
if (@available(iOS 15.0, *)) {
self.tableView.sectionHeaderTopPadding = 0;
}
}
1.iOS15更新之后 导航条突然就白了?一招教你变回来~
1.导航栏变白

2.导航栏字体变黑

3.tabbar
OC:
1.导航栏
BaseNavigationController的viewDidLoad方法里添加:
- (void)viewDidLoad {
[super viewDidLoad];
if (@available(iOS 13.0, *)) {
UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
[appearance configureWithOpaqueBackground];
// 改变导航栏的颜色
appearance.backgroundColor = self.configuration.barTineColor;
// 改变导航栏的标题颜色
appearance.titleTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:18],
NSForegroundColorAttributeName:[UIColor whiteColor]};
//导航栏包含状态栏 阴影线颜色背景色设置
appearance.shadowColor = self.configuration.barTineColor;
// 静止样式
self.navigationBar.standardAppearance = appearance;
// 滚动样式
self.navigationBar.scrollEdgeAppearance = self.navigationBar.standardAppearance;
}
}
2.Tabbar
BaseTabBarController 的 viewDidLoad方法里添加:
- (void)viewDidLoad {
[super viewDidLoad];
if (@available(iOS 13.0, *)) {
UITabBarAppearance *appearance = [UITabBarAppearance new];
[appearance configureWithOpaqueBackground];
appearance.backgroundColor = [UIColor hexColor:0x111423];
self.tabBar.standardAppearance = appearance;
/// 这里有点区别。导航栏是iOS13开始。这里是iOS15才有的
if (@available(iOS 15.0, *)) {
self.tabBar.scrollEdgeAppearance = self.tabBar.standardAppearance;
}
}
}
Swift:
1.导航栏
if #available(iOS 13.0, *) {
let app = UINavigationBarAppearance()
app.configureWithOpaqueBackground() // 重置背景和阴影颜色
app.backgroundEffect = nil //这里设置透明或者不透明
app.titleTextAttributes = [
NSAttributedString.Key.font: UIFont.systemFont(ofSize: 18),
NSAttributedString.Key.foregroundColor: UIColor.white
]
app.backgroundColor = .clear // 设置导航栏背景色
app.shadowColor = nil
UINavigationBar.appearance().scrollEdgeAppearance = nil // 带scroll滑动的页面
UINavigationBar.appearance().standardAppearance = app // 常规页面。描述导航栏以标准高度
}
2.Tabbar
// tabBar
if #available(iOS 13.0, *) {
let itemAppearance = UITabBarItemAppearance()
itemAppearance.normal.titleTextAttributes = [.foregroundColor: NorMal_Color ?? .green]
itemAppearance.selected.titleTextAttributes = [.foregroundColor: Selected_Color ?? .orange]
let appearance = UITabBarAppearance()
appearance.stackedLayoutAppearance = itemAppearance
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = .white
tabBarController?.tabBar.standardAppearance = appearance
if #available(iOS 15.0, *) {
tabBarController?.tabBar.scrollEdgeAppearance = tabBarController?.tabBar.standardAppearance
} else {
// Fallback on earlier versions
}
}
参考:https://baijiahao.baidu.com/s?id=1711749740139600655&wfr=spider&for=pc
造成这个原因是什么呐?
答: 两个因素.
-
scrollEdgeAppearance 属性
-
iOS15 强制适用于所有导航器
当导航控制器包含导航栏和滚动视图时,滚动视图的部分内容将显示在导航栏下方。如果滚动内容的边缘到达该栏,UIKit将在此属性中应用外观设置。如果此属性的值为nil,UIKit将使用standardAppearance属性中的设置,并修改为使用透明背景。如果没有导航控制器管理您的导航栏,UIKit将忽略此属性,并使用导航栏的标准外观。在使用iOS 14或更低版本的应用程序上运行时,此属性适用于标题较大的导航栏。在iOS 15中,此属性适用于所有导航栏。
如何解决.
@NSCopying var scrollEdgeAppearance: UINavigationBarAppearance? { get set }
我们只需要按照UIKit 的最新改动进行适配就好.如下上:
如果设置导航栏透明 ,也会无效。
原因:新的导航栏 在加入 large 模式之后 apple 会对普通模式的 nav 的 _UIbarBackground 进行一次 alpha = 1 的设置。
我们直接改变其 subview 的 alpha 就好了。
解决方法:

3. backgroundImage:背景图片
4. backgroundImageContentMode : 渲染 backgroundImage 时使用的内容模式。 默认为 UIViewContentModeScaleToFill 。
5. shadowColor:底部分割线阴影颜色
6. shadowImage: 阴影图片
//新建一个导航栏
UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
//导航栏包含状态栏重置背景和阴影颜色
[appearance configureWithOpaqueBackground];
//导航栏包含状态栏背景色设置
appearance.backgroundColor = [UIColor colorWithRed:95.0/255.0 green:177.0/255.0 blue:53.0/255.0 alpha:1.0];
//导航栏包含状态栏 阴影线颜色背景色设置
appearance.shadowColor = [UIColor colorWithRed:95.0/255.0 green:177.0/255.0 blue:53.0/255.0 alpha:1.0];
// 常规页面。描述导航栏以标准高度
self.navigationBar.standardAppearance = appearance;
//导航栏包含状态栏带scroll滑动的页面
self.navigationBar.scrollEdgeAppearance = self.navigationBar.standardAppearance;
//设置导航栏为不透明
self.navigationController.navigationBar.translucent = NO;;//iOS7之后由于navigationBar.translucent默认是YES,原点在(0,0)点,当设置NO的时候,原点坐标在(0,64)点
//设置导航栏bar默认颜色
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
//设置导航栏两侧控件颜色(文字颜色)
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
//设置导航栏图片颜色做背景,没有图片iOS13前默认是透明状态
self.navigationController.navigationBar.shadowImage = [UIImage new];
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.subviews.firstObject.alpha = 0;
////2. backgroundColor:注意 这个属性在 backgroundImage 下(在某个界面单独设置导航栏颜色,直接使//用 backgroundColor 无效,被 backgroundImage 遮住了)
//如果设置导航栏透明 ,也会无效。
//原因:新的导航栏 在加入 large 模式之后 apple 会对普通模式的 nav 的 _UIbarBackground 进行一次 alpha //= 1 的设置。
//我们直接改变其 subview 的 alpha 就好了。
浙公网安备 33010602011771号