question

Chris-2757 avatar image
0 Votes"
Chris-2757 asked WenyanZhang-MSFT commented

iOS TabbedRenderer SetTitleTextAttributes not working on iOS 15

Hi, Im using TabbedRenderer with ViewDidAppear and this code:

         if (TabBar.Items != null)
         {
             var items = TabBar.Items;
             foreach (var t in items)
             {
                 t.TitlePositionAdjustment = new UIOffset(0, -14);
                 var txtFont = new UITextAttributes() { Font = UIFont.SystemFontOfSize(18) };
                 t.SetTitleTextAttributes(txtFont, UIControlState.Normal);
             }
         }

         base.ViewDidAppear(animated);

This is no longer working on iOS 15 devices, any ideas? I just want the title text appear a little higher and bigger...

Thanks and best regards
Chris


dotnet-ios
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

WenyanZhang-MSFT avatar image
0 Votes"
WenyanZhang-MSFT answered WenyanZhang-MSFT commented

Hello,

Welcome to our Microsoft Q&A platform!

I create a new TabbedPage and test in iOS15 simulator, it works. But if I add UITabBarItemAppearance , TabBarItem will always be displayed as what I define in UITabBarItemAppearance . These two methods cannot be set at the same time, only one of them will work, you could check if you set UITabBarItemAppearance in other classes.

 [assembly: ExportRenderer(typeof(TabbedPage), typeof(MyTabRenderer_iOS))]
 namespace TestTabDemo.iOS
 {
     public class MyTabRenderer_iOS : TabbedRenderer
     {
         public MyTabRenderer_iOS()
         {
         }
         protected override void OnElementChanged(VisualElementChangedEventArgs e)
         {
             base.OnElementChanged(e);
    
             //var appearance = new UITabBarAppearance();
             //UITabBarItemAppearance tabBarItemAppearance = new UITabBarItemAppearance();
             //appearance.BackgroundColor = UIColor.LightGray;
             //tabBarItemAppearance.Normal.TitleTextAttributes = new UIStringAttributes() { ForegroundColor = UIColor.DarkGray, Font = UIFont.SystemFontOfSize(12) };
             //tabBarItemAppearance.Selected.TitleTextAttributes = new UIStringAttributes() { ForegroundColor = UIColor.Red };
             //appearance.StackedLayoutAppearance = tabBarItemAppearance;
             //UITabBar.Appearance.StandardAppearance = appearance;
             //UITabBar.Appearance.ScrollEdgeAppearance = appearance;
    
         }
         public override void ViewDidAppear(bool animated)
         {
             base.ViewDidAppear(animated);
             var items = TabBar.Items;
             foreach (var t in items)
             {
                 t.TitlePositionAdjustment = new UIOffset(0, -14);
                 t.ImageInsets = new UIEdgeInsets(5, 0, 0, 0);
                 var txtFont = new UITextAttributes() { Font = UIFont.SystemFontOfSize(18) };
                 t.SetTitleTextAttributes(txtFont, UIControlState.Normal);
             }
         }
     }
 }


Best Regards,
Wenyan Zhang


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.


· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I only use public override void ViewDidAppear(bool animated) and this is working for iOS 14 (sim and device), using on iOS 15 is still not working. Using protected override void OnElementChanged(VisualElementChangedEventArgs e) has no effect as well :(

0 Votes 0 ·

You could check if there are any other classes that can customize TabBar, Navigation.
You could also try to add UITabBarItemAppearance in protected override void OnElementChanged(VisualElementChangedEventArgs e) method or in FinishedLaunching method of Appdelegate.cs, refer to the following code:

    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
         {
             global::Xamarin.Forms.Forms.Init();
             LoadApplication(new App());
             var appearance = new UITabBarAppearance();
             UITabBarItemAppearance tabBarItemAppearance = new UITabBarItemAppearance();
             appearance.BackgroundColor = UIColor.LightGray;
             tabBarItemAppearance.Normal.TitleTextAttributes = new UIStringAttributes() { ForegroundColor = UIColor.DarkGray, Font = UIFont.SystemFontOfSize(18) };// you could change the color
             tabBarItemAppearance.Selected.TitleTextAttributes = new UIStringAttributes() { ForegroundColor = UIColor.Red };
             appearance.StackedLayoutAppearance = tabBarItemAppearance;
             UITabBar.Appearance.StandardAppearance = appearance;
             UITabBar.Appearance.ScrollEdgeAppearance = appearance;
    
             return base.FinishedLaunching(app, options);
         }

I still can't reproduce this issue, If the above method doesn't work, I'm afraid you could share a minimal basic reproducible demo to me so that I can test. You could upload it to github and attach the link here.

0 Votes 0 ·

Nothing really changes anything, still problem on iOS 15... Here is a screenshot of iPhone 5s with iOS 11.4, working (using ViewDidAppear) and same code with iPhone 13 with iOS 15...

152488-iphone5s-114.png152469-iphone13-15.png


0 Votes 0 ·
iphone5s-114.png (6.5 KiB)
iphone13-15.png (10.4 KiB)

OK, setting UITabBarItemAppearance in Appdelegate still doesn't work, right? Would you mind sharing a basic reproducible demo? You could upload it to github and attach the link here, it'll help to reproduce the issue to find out the cause.

0 Votes 0 ·