更改TabBar外观

时间:2019-12-12 10:37:36

标签: ios swiftui

我正在尝试使用新的swiftui框架更改tabView外观。我尝试了这个:

appearance.stackedLayoutAppearance.normal.titleTextAttributes = [NSAttributedString.Key.font: UIFont(name: "Lato-Regular", size: 11)!]
appearance.stackedLayoutAppearance.normal.titleTextAttributes = [NSAttributedString.Key.foregroundColor: Color.TabViewItemNormalColor.uiColor()]

appearance.stackedLayoutAppearance.selected.titleTextAttributes = [NSAttributedString.Key.font: UIFont(name: "Lato-Regular", size: 11)!]
appearance.stackedLayoutAppearance.selected.titleTextAttributes = [NSAttributedString.Key.foregroundColor: Color.TabViewItemNormalColor.uiColor()]

但是只有文本颜色改变了,字体与以前的一样

1 个答案:

答案 0 :(得分:0)

尝试以下

appearance.stackedLayoutAppearance.normal.titleTextAttributes = [
    NSAttributedString.Key.font: UIFont(name: "Lato-Regular", size: 11)!,
    NSAttributedString.Key.foregroundColor: Color.TabViewItemNormalColor.uiColor()
]

appearance.stackedLayoutAppearance.selected.titleTextAttributes =  [
    NSAttributedString.Key.font: UIFont(name: "Lato-Regular", size: 11)!, 
    NSAttributedString.Key.foregroundColor: Color.TabViewItemNormalColor.uiColor()
]