提问人:Chander Dhiman 提问时间:8/22/2023 更新时间:8/22/2023 访问量:20
我垫标签栏未选择的项目颜色没有改变,但在 iPhone 中工作正常
i pad tab bar unselected item color is not changing but working fine in iphone
问:
我正在使用 Xcode 版本 14.3.1 。最低部署目标 12.0。在iPhone中,一切正常,但在I Pad中,所选项目颜色正在更改,但未选择的项目颜色不会更改。
我也想在iPad中获取选定的未选择颜色
答:
0赞
Parul Garg
8/22/2023
#1
let tabBarAppearnace = UITabBarAppearance()
let tabFont = UIFont.boldSystemFont(ofSize: 16)
let selectedAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.font: tabFont, NSAttributedString.Key.foregroundColor: UIColor.white]
let normalAttributes: [NSAttributedString.Key: Any]
= [NSAttributedString.Key.font: tabFont, NSAttributedString.Key.foregroundColor: UIColor.red]
tabBarAppearnace.stackedLayoutAppearance.normal.titleTextAttributes = normalAttributes
tabBarAppearnace.stackedLayoutAppearance.selected.titleTextAttributes = selectedAttributes
tabBar.standardAppearance = tabBarAppearnace
如果上述方法不起作用,请尝试下面提到的代码
tabBarAppearnace.inlineLayoutAppearance.normal.titleTextAttributes = normalAttributes
tabBarAppearnace.inlineLayoutAppearance.selected.titleTextAttributes = selectedAttributes
tabBarAppearnace.compactInlineLayoutAppearance.normal.titleTextAttributes = normalAttributes
tabBarAppearnace.compactInlineLayoutAppearance.selected.titleTextAttributes = selectedAttributes
评论