change sf symbol weight/size in TabView

1.7k views Asked by At

This a a sample TabBar code:

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("")
            }
         
    }
}
}

How do I change the font and size of icons/text? Have already tried .font(.system(size: 30, weight: .bold)) after Image(systemName: "Any") and after TabView brace and none worked.

1

There are 1 answers

3
davidev On BEST ANSWER

You can change the font of the tab bar like this:

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)
}

However, I am not aware if you can change the image size. I think the icon in tab bar have a fixed size. Not sure if you can change them in UIKIt

Edit: You can just pass any UIFont. If you want a different weight there is systemFont(ofSize: weight:) available like this

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

enter image description here