ios – Change font of tab bar labels?

0
15
ios – Change font of tab bar labels?


I am making an attempt to implement a customized font (OpenSans) in my SwiftUI app.

Most of my views are completely satisfied to take the font and I do know due to this fact that it is being loaded from the bundle accurately. Nonetheless, there are a few locations it is being problematic.

The primary was the navigation bar, however I used to be in a position to make use of the looks proxy to switch the titleTextAttributes dictionary to unravel this.

The opposite problematic half, and the one I’ve not but been in a position to resolve, the tab bar buttons. Wherever I attempt to modify the font, it seemingly would not work – maybe the TabView APIs internally are modifying the font again? Here is what I’ve tried (I am utilizing SwiftGen for useful resource accessors):

  • Making use of the font modifier to a Label view offered by the tabItem modifier (

    TabView {
        Textual content("My tab content material right here...")
            .tabItem {
                Label(
                    title: {
                        Textual content(SFAssetVerificationUI.L10n.audits)
                            .font(FontFamily.OpenSans.extraBold.swiftUIFont(fixedSize: 18))
                    },
                    icon: { SFAssetVerificationUI.Asset.icTabAudits.swiftUIImage }
                )
            }
    }
    

  • Making use of the font modifier to a Label view offered because the label argument to a Tab view (>=iOS 18).

    TabView {
        Tab(
            content material: {
                Textual content("My tab content material right here...")  
            },
            label: {
                Label(
                    title: {
                        Textual content(SFAssetVerificationUI.L10n.audits)
                            .font(FontFamily.OpenSans.extraBold.swiftUIFont(fixedSize: 18))
                    },
                    icon: { SFAssetVerificationUI.Asset.icTabAudits.swiftUIImage }
                )
            }
        )
    }
    
  • Swapping out each the above Label views for a VStack containing an Picture view and a Textual content view.

    TabView {
        Tab(
            content material: {
                Textual content("My tab content material right here...")  
            },
            label: {
                VStack {
                    SFAssetVerificationUI.Asset.icTabAudits.swiftUIImage
                    Textual content(SFAssetVerificationUI.L10n.audits)
                        .font(FontFamily.OpenSans.extraBold.swiftUIFont(fixedSize: 18))
                }
            }
        )
    }
    
  • Setting titleTextAttributes on the UITabBarItem look proxy, for each regular and chosen states.

    UITabBarItem.look().setTitleTextAttributes([.font: FontFamily.OpenSans.extraBold.font(size: 18)], for: .regular)
    UITabBarItem.look().setTitleTextAttributes([.font: FontFamily.OpenSans.extraBold.font(size: 18)], for: .chosen)
    

LEAVE A REPLY

Please enter your comment!
Please enter your name here