IOS 26 Uitabbarapearance Force Dark ModeIOS

Программируем под IOS
Ответить Пред. темаСлед. тема
Anonymous
 IOS 26 Uitabbarapearance Force Dark Mode

Сообщение Anonymous »

Я пытаюсь заставить свое приложение внедрить нижнюю панель вкладок в темный режим, когда система все еще находится в режиме света (переопределение темного режима). Очевидно, я могу заставить его работать

Код: Выделить всё

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 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • IOS 26 Uitabbarapearance Force Dark Mode
    Anonymous » » в форуме IOS
    0 Ответы
    2 Просмотры
    Последнее сообщение Anonymous
  • Uitabbarapparance Force Dark Mode [закрыто]
    Anonymous » » в форуме IOS
    0 Ответы
    5 Просмотры
    Последнее сообщение Anonymous
  • React Native Expo с NativeWind портит стили с помощью Razorpay и Dark Mode
    Anonymous » » в форуме Android
    0 Ответы
    54 Просмотры
    Последнее сообщение Anonymous
  • Преодолеть Outlook Dark Mode Color Invert
    Anonymous » » в форуме CSS
    0 Ответы
    9 Просмотры
    Последнее сообщение Anonymous
  • Преодолеть Outlook Dark Mode Color Invert
    Anonymous » » в форуме CSS
    0 Ответы
    12 Просмотры
    Последнее сообщение Anonymous

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