在iOS 15
中导航栏出现如下情况:
在storyboard
按下图设置
或者在 UINavigationController
中加入如下代码即可
// navigationBar
if #available(iOS 13.0, *) {
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = NorMal_Color
appearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
navigationBar.standardAppearance = appearance
navigationBar.scrollEdgeAppearance = navigationBar.standardAppearance
} else {
UINavigationBar.appearance().barTintColor = NorMal_Color
UINavigationBar.appearance().titleTextAttributes = [.foregroundColor: UIColor.white]
UINavigationBar.appearance().tintColor = .white
}
tababr
在iOS 15
中出现下图情况
在storyboard
中如下图设置即可
也可用代码实现:
// 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
}
}