我有UITabBarConroller
子类和自定义项。自定义如下所示:
private func updateTabBar() {
guard let items = tabBar.items,
tabViewControllers.count == items.count else {
return
}
for (item, vc) in zip(items, tabViewControllers) {
// setting items title, image, selectedImage ...
item.setTitleTextAttributes(Self.normalAttributes, for: .normal)
item.badgeColor = .customColor
}
}
这在iOS 14和更早的版本上运行良好。但不是在iOS 15上。我找到了一些关于scrollEdgeAppearance
的信息。这可以防止黑色背景。但是设置彩色文本属性和徽章颜色被忽略。问题是如何在UITabBarItem
上设置自定义文本颜色和徽章颜色
发布于 2021-09-28 03:55:54
最后,我做到了。我在寻找stackedLayoutAppearance
及其属性iconColor
和badgeBackgroundColor
。根据您的项目,您可能还需要inlineLayoutAppearance
或compactInlineLayoutAppearance
。
@available(iOS 13.0, *)
private static let tabBarAppearance: UITabBarAppearance = {
let appearance = UITabBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = .customBackgroundColor
appearance.stackedLayoutAppearance.normal.iconColor = .customTitleColorForNormalState
appearance.stackedLayoutAppearance.normal.titleTextAttributes = normalAttributes
appearance.stackedLayoutAppearance.selected.titleTextAttributes = normalAttributes
appearance.stackedLayoutAppearance.normal.badgeBackgroundColor = .customBadgeColor
return appearance
}()
if #available(iOS 13.0, *) {
item.standardAppearance = Self.tabBarAppearance
if #available(iOS 15.0, *) {
item.scrollEdgeAppearance = item.standardAppearance
}
}
https://stackoverflow.com/questions/69359899
复制相似问题