Uitabbarapparance Force Dark Mode [закрыто]IOS

Программируем под IOS
Ответить Пред. темаСлед. тема
Anonymous
 Uitabbarapparance Force Dark Mode [закрыто]

Сообщение Anonymous »

Я пытаюсь внедрить нижнюю панель вкладок в темный режим, когда система все еще находится в режиме света (переопределение темного режима). Я могу заставить его работать в 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
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Dark Mode vs. Light Mode: который лучше всего подходит для новостных приложений? [закрыто]
    Anonymous » » в форуме Android
    0 Ответы
    1 Просмотры
    Последнее сообщение Anonymous
  • IOS 26 Uitabbarapearance Force Dark Mode
    Anonymous » » в форуме IOS
    0 Ответы
    2 Просмотры
    Последнее сообщение Anonymous
  • IOS 26 Uitabbarapearance Force Dark Mode
    Anonymous » » в форуме IOS
    0 Ответы
    4 Просмотры
    Последнее сообщение Anonymous
  • Невозможно реализовать Dark Mode на веб -сайте HTML с помощью JS, он не применяется [закрыто]
    Anonymous » » в форуме Javascript
    0 Ответы
    4 Просмотры
    Последнее сообщение Anonymous
  • React Native Expo с NativeWind портит стили с помощью Razorpay и Dark Mode
    Anonymous » » в форуме Android
    0 Ответы
    56 Просмотры
    Последнее сообщение Anonymous

Вернуться в «IOS»