В iOS 13 стандартный внешний вид UITabBarItem применяется ко всем остальным элементам - PullRequest
1 голос
/ 22 октября 2019

Я пытаюсь сделать простую вещь на iOS 13 - последний элемент панели вкладок всегда должен отображаться другим цветом .

Я пытался использовать новый UITabBarItem.standardAppearance участник. Вот мои коды:

// first, set the default colors for the whole tab bar
let color = Style.Color.tabItem
let text = [NSAttributedString.Key.foregroundColor: color]
let selectedColor = Style.Color.tabItemSelected
let selectedText = [NSAttributedString.Key.foregroundColor: selectedColor]

let barAppearance = UITabBarItemAppearance()

barAppearance.normal.iconColor = color
barAppearance.disabled.iconColor = color
barAppearance.selected.iconColor = selectedColor
barAppearance.focused.iconColor = selectedColor

barAppearance.normal.titleTextAttributes = text
barAppearance.disabled.titleTextAttributes = text
barAppearance.selected.titleTextAttributes = selectedText
barAppearance.focused.titleTextAttributes = selectedText

tabBar.standardAppearance.stackedLayoutAppearance = barAppearance
tabBar.standardAppearance.inlineLayoutAppearance = barAppearance
tabBar.standardAppearance.compactInlineLayoutAppearance = barAppearance
tabBar.standardAppearance.backgroundColor = Style.Color.tabBar

// now, for the last item set special colors
if let lastItem = tabBar.items?.last {
    let specialColor = Style.Color.tabItemSpecial
    let specialText = [NSAttributedString.Key.foregroundColor: specialColor]
    let specialSelectedColor = Style.Color.tabItemSpecialSelected
    let specialSelectedText = [NSAttributedString.Key.foregroundColor: specialSelectedColor]

    let itemAppearance = UITabBarItemAppearance()

    itemAppearance.normal.iconColor = specialColor
    itemAppearance.disabled.iconColor = specialColor
    itemAppearance.selected.iconColor = specialSelectedColor
    itemAppearance.focused.iconColor = specialSelectedColor

    itemAppearance.normal.titleTextAttributes = specialText
    itemAppearance.disabled.titleTextAttributes = specialText
    itemAppearance.selected.titleTextAttributes = specialSelectedText
    itemAppearance.focused.titleTextAttributes = specialSelectedText

    let itemBarAppearance = UITabBarAppearance()

    itemBarAppearance.stackedLayoutAppearance = itemAppearance
    itemBarAppearance.inlineLayoutAppearance = itemAppearance
    itemBarAppearance.compactInlineLayoutAppearance = itemAppearance
    itemBarAppearance.backgroundColor = Style.Color.tabBar

    lastItem.standardAppearance = itemBarAppearance
}

Ожидаемое поведение:

Все элементы вкладки ВСЕГДА показаны в tabItem / tabItemSelectedцвета, последний элемент вкладки ВСЕГДА показан в tabItemSpecial / tabItemSpecialSelected color.

Фактическое поведение:

Когда любой изэлементы выбраны, кроме последнего - все элементы вкладок отображаются в tabItem / tabItemSelected, , включая последний ! Когда я выбираю последний элемент панели вкладок, применяется стиль standardAppearance TO ALL и другие элементы панели вкладок! Поэтому все они используют tabItemSpecial / tabItemSpecialSelected цветовую схему.

Я что-то не так делаю? Или, может быть, я неправильно понял новые API, и нет способа, чтобы один элемент панели вкладок всегда имел другой цвет?

1 Ответ

0 голосов
/ 23 октября 2019

Это ожидаемое поведение. Вы не настраиваете, как выглядит конкретный элемент панели вкладок, вы настраиваете, как выглядит панель вкладок, когда этот элемент выбран в данный момент.

...