【发布时间】:2021-11-11 23:39:39
【问题描述】:
我创建了一个简单的演示,只创建了一个 UITabBarController 的子类并在 storyboard 中设置。
我想将 TabBarButtonItem 的标题设置为选中时的橙色和正常时的黑色。以下代码在 iPhone 上的任何 iOS 版本上都可以正常工作,但在 iOS 15 的 iPad(设备和模拟器)上,所选颜色变为蓝色和有线正常状态颜色。
这是 Apple 的错误还是我遗漏了什么?(我使用的是 Xcode13)
class CustomViewController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
let tabBarAppearnace = UITabBarAppearance()
let tabFont = UIFont.boldSystemFont(ofSize: 18)
let selectedAttributes: [NSAttributedString.Key: Any]
= [NSAttributedString.Key.font: tabFont, NSAttributedString.Key.foregroundColor: UIColor.orange]
let normalAttributes: [NSAttributedString.Key: Any]
= [NSAttributedString.Key.font: tabFont, NSAttributedString.Key.foregroundColor: UIColor.black]
tabBarAppearnace.stackedLayoutAppearance.normal.titleTextAttributes = normalAttributes
tabBarAppearnace.stackedLayoutAppearance.selected.titleTextAttributes = selectedAttributes
tabBar.standardAppearance = tabBarAppearnace
}
}
【问题讨论】:
标签: ios swift uitabbaritem ios15