In my Xamarin iOS app I am trying to hide the top border and change the font family of TabbedPage. For Xamarin version 5.0.0.2021 it works fine. However when I update Xamarin version to 5.0.0.2244 it doesn't seem to work? There must be something unusual here. This is how I changed the font Family and Border Top TabbedPage:
MyTabbedPageRenderer
Change icon size, fontsize, font family,... TabbedPage
[assembly: ExportRenderer(typeof(TabbedPage), typeof(MyTabbedPageRenderer))]
....
public class MyTabbedPageRenderer : TabbedRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
TabBar.TintColor = UIColor.Gray;
TabBar.BarTintColor = UIColor.White;
TabBar.BackgroundColor = UIColor.White;
}
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
if (TabBar?.Items == null)
return;
foreach (var item in TabBar.Items)
{
item.Image = ScalingImageToSize(item.Image, new CGSize(30, 30)); // set the size here as you want
}
var tabs = Element as TabbedPage;
if (tabs != null)
{
for (int i = 0; i < TabBar.Items.Length; i )
{
UpdateTabBarItem(TabBar.Items[i]);
}
}
}
private void UpdateTabBarItem(UITabBarItem item)
{
if (item == null)
return;
// Set the font for the title.
item.SetTitleTextAttributes(new UITextAttributes() { Font = UIFont.FromName("Quicksand Regular", 12), TextColor = Color.FromHex("#808080").ToUIColor() }, UIControlState.Normal);
item.SetTitleTextAttributes(new UITextAttributes() { Font = UIFont.FromName("Quicksand Regular", 13), TextColor = Color.FromHex("#00AA13").ToUIColor() }, UIControlState.Selected);
}
...
}
Remove border top TabbedPage
AppDelegate
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
UITabBar.Appearance.BackgroundImage = new UIImage();
UITabBar.Appearance.ShadowImage = new UIImage();
UITabBar.Appearance.SelectedImageTintColor = UIColor.FromRGB(0, 170, 19);
LoadApplication(new App());
}
I tried rebuilding the project, restarting everything, but it doesn't seem to work on Xamarin version 5.0.0.2244. Ask for help. Thanks.
CodePudding user response:
There are some api changes in iOS 15, so we need to change the way .
Remove border top
TabBar.ClipsToBounds = true;
Change the font and text color on items
private void UpdateTabBarItem(UITabBarItem item)
{
if (item == null) return;
if(UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
{
UITabBarAppearance app = new UITabBarAppearance();
app.ConfigureWithOpaqueBackground();
app.BackgroundColor = UIColor.Clear;
app.StackedLayoutAppearance.Normal.TitleTextAttributes = new UIStringAttributes() { Font = UIFont.FromName("GillSans-UltraBold", 12), ForegroundColor = Color.FromHex("#00FF00").ToUIColor() };
app.StackedLayoutAppearance.Selected.TitleTextAttributes = new UIStringAttributes() { Font = UIFont.FromName("GillSans-UltraBold", 20), ForegroundColor = Color.FromHex("#FF0000").ToUIColor() };
item.StandardAppearance = app;
if (UIDevice.CurrentDevice.CheckSystemVersion(15, 0))
{
item.ScrollEdgeAppearance = item.StandardAppearance;
}
}
}
Tested on my side , works fine .
Refer to