升级Xcode13后,编译的APP的导航栏(nav、tabbar)、tableview的section head会出现一些显示问题,在这里给出一些处理方法。
UINavigationBar
Swift
if #available(iOS 13.0, *) {
let appearance = UINavigationBarAppearance()
// 设置导航栏背景色
appearance.backgroundColor = .white
// 去除导航栏阴影(如果不设置clear,导航栏底下会有一条阴影线)
appearance.shadowColor = UIColor.clear
// 字体颜色
appearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
// 带scroll滑动的页面
navigationController?.navigationBar.scrollEdgeAppearance = appearance
// 常规页面
navigationController?.navigationBar.standardAppearance = appearance
}
Objective-C
if (@available(iOS 13.0, *)) {
UINavigationBarAppearance * appearance = [[UINavigationBarAppearance alloc] init];
// 背景色
appearance.backgroundColor = [UIColor whiteColor];
// 去除导航栏阴影(如果不设置clear,导航栏底下会有一条阴影线)
appearance.shadowColor = [UIColor clearColor];
// 字体颜色
appearance.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor redColor]};
// 带scroll滑动的页面
self.navigationController.navigationBar.scrollEdgeAppearance = appearance;
// 常规页面
self.navigationController.navigationBar.standardAppearance = appearance;
}
UITabbar
Swift
if #available(iOS 13.0, *) {
let appearance = UITabBarAppearance()
// 背景色
appearance.backgroundColor = .white
tabBar.standardAppearance = appearance
if #available(iOS 15.0, *) {
tabBar.scrollEdgeAppearance = appearance
}
}
Objective-C
if (@available(iOS 13.0, *)) {
UITabBarAppearance *appearance = [[UITabBarAppearance alloc] init];
// 背景色
appearance.backgroundColor = [UIColor whiteColor];
self.tabBar.standardAppearance = appearance;
if (@available(iOS 15.0, *)) {
self.tabBar.scrollEdgeAppearance = appearance;
}
}
TableView
iOS 15 的 UITableView 新增了一条新属性:sectionHeaderTopPadding, 默认会给每一个 section header 增加 22px。
Swift
if #available(iOS 15.0, *) {
tableView.sectionHeaderTopPadding = 0
}
Objective-C
if (@available(iOS 15.0, *)) {
tableView.sectionHeaderTopPadding = 0;
}
|