Xamarin表单iOS渲染器 – 工具栏标准图标

前端之家收集整理的这篇文章主要介绍了Xamarin表单iOS渲染器 – 工具栏标准图标前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我可以创建一个简单的Tab渲染器,它将更新我的Forms ToolBarItems以使用内置的iOS图标,如下所示.

NavigationController在ViewWillAppear中只有NOT NULL如果我在ViewDidLoad中尝试,则为NULL.

这样做的问题是,在使用实际图标替换之前,您将收到TabBar Item文本的闪光.

有不同的地方我应该拦截ToolBar的行为?

[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();
            }
        }
    }
}

解决方法

覆盖OnElementChanged方法
protected override void OnElementChanged(VisualElementChangedEventArgs e)
    {
        base.OnElementChanged(e);

        if(e.NewElement!= null)
        {
            var list = new List<UIBarButtonItem>();

            // Your code goes here
        }
    }
原文链接:https://www.f2er.com/html/225120.html

猜你在找的HTML相关文章