if #available(iOS 13.0, *) {
let tabBarAppearance = UITabBarAppearance()
// UITabBarItem 选择颜色和字体大小
tabBarAppearance.stackedLayoutAppearance.normal.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black,NSAttributedString.Key.font:UIFont.systemFont(ofSize: 10)]
tabBarAppearance.stackedLayoutAppearance.selected.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.red,NSAttributedString.Key.font:UIFont.systemFont(ofSize: 10)]
// UITabBarItem 文字的偏移量
tabBarAppearance.stackedLayoutAppearance.normal.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -3)
// tabBar 颜色
tabBarAppearance.backgroundColor = .white
// tabBar 背景图片
tabBarAppearance.backgroundImage = UIImage(named: "abc")
// 这句一定要放在最后
tabBar.standardAppearance = tabBarAppearance
} else {
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.black,NSAttributedString.Key.font:UIFont.systemFont(ofSize: 10)], for: .normal)
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.red,NSAttributedString.Key.font:UIFont.systemFont(ofSize: 10)], for: .selected)
UITabBarItem.appearance().titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -3)
// tabBar 颜色
UITabBar.appearance().backgroundColor = .white
// tabBar 背景图片
UITabBar.appearance().backgroundImage = UIImage(named: "abc")
}