How To Change Shell Tab Font to Custom Font - iOS SDK 15

Aziz 1 Reputation point
2022-06-10T21:34:01.303+00:00

Hi There,

In SDK 14, I was able to change the font of the shell tab by simply having the font *.ttf in the resources folder and adding these two lines in FinishedLaunching

UITabBarItem.Appearance.SetTitleTextAttributes(new UITextAttributes() { Font = UIFont.FromName("MY_FONT_NAME", 10), }, UIControlState.Normal);  
UITabBarItem.Appearance.SetTitleTextAttributes(new UITextAttributes() { Font = UIFont.FromName("MY_FONT_NAME", 10), }, UIControlState.Selected);   

However, when compiling with SDK 15, this no longer works! Any quick workaround to change the font of the shell?
Thanks,

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,293 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 35,291 Reputation points Microsoft Vendor
    2022-06-13T07:31:25.94+00:00

    Hello,

    You could use Renderer to implement this function.

    Referring to this official sample customize-tabs, we could find the details about how to deal with it in ExtendedTabbedPageRenderer.cs.

    Another way is setting the UITabBarAppearance property manually, you can refer the following key code.

       private static UITabBarAppearance tabBarAppearance()  
       {  
           var appearance = new UITabBarAppearance();  
           appearance.ConfigureWithOpaqueBackground();  
           appearance.BackgroundColor = UIColor.White;  
           appearance.StackedLayoutAppearance.Normal.TitleTextAttributes = new UIStringAttributes() { Font = UIFont.FromName("MY_FONT_NAME", 10), };  
           appearance.StackedLayoutAppearance.Selected.TitleTextAttributes = new UIStringAttributes() { Font = UIFont.FromName("MY_FONT_NAME", 10), };  
           return appearance;  
       }  
         
       ...  
       tabBar.ScrollEdgeAppearance = appearance;  
       tabBar.StandardAppearance = appearance;  
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments