Exemplo n.º 1
0
        void UpdateIcon(ToolbarItemEx itemEx, UIBarButtonItem nativeItem)
        {
            itemEx.PropertyChanged -= ItemEx_PropertyChanged;
            itemEx.PropertyChanged += ItemEx_PropertyChanged;

            if (!itemEx.IsVisible)
            {
                nativeItem.Image = null;
                nativeItem.Title = null;
                return;
            }
            if (string.IsNullOrEmpty(itemEx.Resource))
            {
                return;
            }

            nativeItem.Image   = SvgToUIImage.GetUIImage(itemEx.Resource, 20, 20);
            nativeItem.Title   = null;
            nativeItem.Style   = UIBarButtonItemStyle.Plain;
            nativeItem.Enabled = itemEx.IsEnabled;
        }
Exemplo n.º 2
0
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            var tabbedEx = Element as TabbedPageEx;

            UITabBarController tabctrl = Platform.GetRenderer(Tabbed.Children[0]).ViewController.TabBarController;

            for (var i = 0; i < Tabbed.Children.Count; i++)
            {
                Page child = Tabbed.Children[i];
                var  attr  = tabbedEx.TabAttributes[i];

                if (child is NavigationPageEx)
                {
                    var naviEx = child as NavigationPageEx;

                    naviEx.BarTextColor = tabbedEx.BarTextColor;
                    if (attr.BarTextColor != Xamarin.Forms.Color.Default)
                    {
                        naviEx.BarTextColor = attr.BarTextColor;
                    }
                }

                if (string.IsNullOrEmpty(attr.Resource))
                {
                    continue;
                }
                var vc = Platform.GetRenderer(child).ViewController;

                if (tabbedEx.IsDefaultColor && attr.IsDefaultColor)
                {
                    var icon = SvgToUIImage.GetUIImage(attr.Resource, 30, 30);
                    vc.TabBarItem.Image = icon;
                }
                else
                {
                    vc.TabBarItem.Title = attr.Title;
                    vc.TabBarItem.SetTitleTextAttributes(
                        new UITextAttributes {
                        TextColor = tabbedEx.SelectedTextColor.ToUIColor()
                    },
                        UIControlState.Selected
                        );
                    vc.TabBarItem.SetTitleTextAttributes(
                        new UITextAttributes {
                        TextColor = tabbedEx.UnSelectedTextColor.ToUIColor()
                    },
                        UIControlState.Normal
                        );

                    var selColor = attr.SelectedColor == Xamarin.Forms.Color.Default ? tabbedEx.SelectedColor : attr.SelectedColor;
                    var unColor  = attr.UnSelectedColor == Xamarin.Forms.Color.Default ? tabbedEx.UnSelectedColor : attr.UnSelectedColor;
                    var icon1    = SvgToUIImage.GetUIImage(attr.Resource, 30, 30, selColor);
                    var icon2    = SvgToUIImage.GetUIImage(attr.Resource, 30, 30, unColor);
                    vc.TabBarItem.SetFinishedImages(icon1, icon2);
                }

                if (tabbedEx.IsTextHidden)
                {
                    vc.TabBarItem.Title       = null;
                    vc.TabBarItem.ImageInsets = new UIEdgeInsets(6, 0, -6, 0);
                }
            }

            if (!tabbedEx.IsDefaultColor)
            {
                tabctrl.TabBar.TintColor = (Element as TabbedPageEx).SelectedTextColor.ToUIColor();
            }
        }