I can create a simple Tab Renderer which will update my Forms ToolBarItems to use the built in iOS icons like below.
NavigationController
is only NOT NULL
in ViewWillAppear
If I try it in ViewDidLoad
, it is NULL
.
The problem with this is you get a flash of the TabBar Item text before it gets replaced with the actual icon.
Is there a different place I should be intercepting the ToolBar behavior?
[assembly: ExportRenderer(typeof(TabbedPage), typeof(TabRenderer))]
namespace Cellar.iOS.Renders
{
public class TabRenderer : TabbedRenderer
{
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
var list = new List<UIBarButtonItem>();
foreach (var item in NavigationController.TopViewController.NavigationItem.RightBarButtonItems)
{
if (string.IsNullOrEmpty(item.Title))
{
continue;
}
if (item.Title.ToLower() == "add")
{
var newItem = new UIBarButtonItem(UIBarButtonSystemItem.Add)
{
Action = item.Action,
Target = item.Target
};
list.Add(newItem);
}
if (list.Count > 0)
NavigationController.TopViewController.NavigationItem.RightBarButtonItems = list.ToArray();
}
}
}
}
override OnElementChanged
method:
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if(e.NewElement!= null)
{
var list = new List<UIBarButtonItem>();
// Your code goes here
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With