首页 > 解决方案 > 在 TabView 中更改 sf 符号的重量/大小

问题描述

这是一个示例 TabBar 代码:

struct TabBar: View{
@State var current = 0
var body: some View{
    TabView(selection: $current) {
        
         View0()
            .tag(0)
            .tabItem {
                Image(systemName: "anySystemImageName")
                Text("")
            }
         View1()
            .tag(1)
            .tabItem {
                Image(systemName: "anySystemImageName")
                Text("")
            }
         
    }
}
}

如何更改图标/文本的字体和大小?已经.font(.system(size: 30, weight: .bold))在 Image(systemName: "Any") 和TabView大括号之后尝试过,但都没有工作。

标签: swiftswiftuisizetabbarsf-symbols

解决方案


您可以像这样更改标签栏的字体:

init() {
    UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.font: UIFont.systemFont(ofSize: 20)], for: .normal)
    UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.font: UIFont.systemFont(ofSize: 20)], for: .selected)
}

但是,我不知道您是否可以更改图像大小。我认为标签栏中的图标具有固定大小。不确定您是否可以更改它们UIKIt

编辑:您可以通过任何 UIFont。如果您想要不同的重量,可以使用 systemFont(ofSize: weight:) 像这样

UIFont.systemFont(ofSize: 20, weight: .bold)

在此处输入图像描述


推荐阅读