Код: Выделить всё
overrideUserInterfaceStyle = .dark
let appearance = UITabBarAppearance()
if #available(iOS 26, *) {
appearance.configureWithDefaultBackground()
}
< /code>
appdelegate: < /p>
if #available(iOS 26, *) {
// no styling override
} else {
//navbar
let newNavBarApperance = PAppearance().getNavAppearance(style: .light)
let navAppearance = UINavigationBar.appearance()
navAppearance.standardAppearance = newNavBarApperance
navAppearance.tintColor = UIColor.white
navAppearance.isTranslucent = false
//tabbar
let newTabBarAppearance = PAppearance().getTabAppearance(style: .light)
let tabAppearance = UITabBar.appearance()
tabAppearance.standardAppearance = newTabBarAppearance
tabAppearance.tintColor = UIColor.white
tabAppearance.unselectedItemTintColor = UIColor.lightGray
tabAppearance.isTranslucent = false
navAppearance.scrollEdgeAppearance = newNavBarApperance
tabAppearance.scrollEdgeAppearance = newTabBarAppearance
}
< /code>
pappearance: < /p>
static func makeTabBarAppearance(style: themeStyle) -> UITabBarAppearance {
let appearance = UITabBarAppearance()
if #available(iOS 26, *) {
appearance.configureWithDefaultBackground()
} else {
appearance.configureWithOpaqueBackground()
}
switch style {
case .dark:
if #unavailable(iOS 26) {
appearance.backgroundColor = .black
appearance.stackedLayoutAppearance.selected.iconColor = .white
appearance.stackedLayoutAppearance.selected.titleTextAttributes = [.foregroundColor: UIColor.white]
appearance.stackedLayoutAppearance.normal.iconColor = .white
appearance.stackedLayoutAppearance.normal.titleTextAttributes = [.foregroundColor: UIColor.white]
}
case .light:
if #unavailable(iOS 26) {
appearance.backgroundColor = UIColor(named: "Default") ?? .systemBackground
appearance.stackedLayoutAppearance.selected.iconColor = .white
appearance.stackedLayoutAppearance.selected.titleTextAttributes = [.foregroundColor: UIColor.white]
appearance.stackedLayoutAppearance.normal.iconColor = .white
appearance.stackedLayoutAppearance.normal.titleTextAttributes = [.foregroundColor: UIColor.white]
} else {
let selectedColor = UIColor.label
let normalColor = UIColor.secondaryLabel
appearance.stackedLayoutAppearance.selected.iconColor = selectedColor
appearance.stackedLayoutAppearance.selected.titleTextAttributes = [.foregroundColor: selectedColor]
appearance.stackedLayoutAppearance.normal.iconColor = normalColor
appearance.stackedLayoutAppearance.normal.titleTextAttributes = [.foregroundColor: normalColor]
}
}
return appearance
}
< /code>
ViewController: < /p>
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
guard UIApplication.shared.applicationState == .inactive else {
return
}
themeCheck()
}
func themeCheck() {
let theme = SharedPrefs.getPrefsStringValue(name: .theme)
switch theme {
case ThemeOverride.system.rawValue:
overrideUserInterfaceStyle = .unspecified
case ThemeOverride.light.rawValue:
overrideUserInterfaceStyle = .light
case ThemeOverride.dark.rawValue:
overrideUserInterfaceStyle = .dark
default:
overrideUserInterfaceStyle = .unspecified
}
updateNavBarForCurrentInterfaceStyle()
}
func updateNavBarForCurrentInterfaceStyle(){
let style: PAppearance.themeStyle =
traitCollection.userInterfaceStyle == .dark ? .dark : .light
let navAppearance = PAppearance.makeNavigationAppearance(style: style)
let tabAppearance = PAppearance.makeTabBarAppearance(style: style)
navigationController?.navigationBar.standardAppearance = navAppearance
navigationController?.navigationBar.scrollEdgeAppearance = navAppearance
tabBarController?.tabBar.standardAppearance = tabAppearance
tabBarController?.tabBar.scrollEdgeAppearance = tabAppearance
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... -dark-mode