Программируем под IOS
Anonymous
Uitabbarapparance Force Dark Mode [закрыто]
Сообщение
Anonymous » 25 июл 2025, 01:03
Я пытаюсь внедрить нижнюю панель вкладок в темный режим, когда система все еще находится в режиме света (переопределение темного режима). Я могу заставить его работать в iOS ниже V26, но, похоже, нет способа заставить нижнюю панель в темный режим. Вся документация переопределяет черту и использует ConfigureWithDefaultbackground . Это работает с навигационной панелью. Я заставил его работать, положив к нему вид (только для тестирования), и это меняется соответственно. Я бы не хотел. Навигация делает то же самое с текстом, он не меняется, пока вид, стоящий за ним, не изменится. И фон viewController Фон не считается.
Код: Выделить всё
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
1753394616
Anonymous
Я пытаюсь внедрить нижнюю панель вкладок в темный режим, когда система все еще находится в режиме света (переопределение темного режима). Я могу заставить его работать в iOS ниже V26, но, похоже, нет способа заставить нижнюю панель в темный режим. Вся документация переопределяет черту и использует ConfigureWithDefaultbackground . Это работает с навигационной панелью. Я заставил его работать, положив к нему вид (только для тестирования), и это меняется соответственно. Я бы не хотел. Навигация делает то же самое с текстом, он не меняется, пока вид, стоящий за ним, не изменится. И фон viewController Фон не считается.[code]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 } [/code] Подробнее здесь: [url]https://stackoverflow.com/questions/79697423/uitabbarappearance-force-dark-mode[/url]