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 thetabItem
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 thelabel
argument to aTab
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 aVStack
containing anPicture
view and aTextual 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 theUITabBarItem
look proxy, for eachregular
andchosen
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)