コード例 #1
0
ファイル: TabBar.cs プロジェクト: delort/Material-Xamarin-iOS
        public override void LayoutSubviews()
        {
            base.LayoutSubviews();
            if (WillLayout && 0 < Buttons.Count)
            {
                foreach (var b in Buttons)
                {
                    b.Grid().Columns = 0;
                    b.SetCornerRadius(0);
                    b.ContentEdgeInsets = UIEdgeInsets.Zero;

                    if (IsLineAnimated)
                    {
                        prepareLineAnimationHandler(b);
                    }
                }

                ContentView.Grid().Reload();

                if (Selected == null)
                {
                    Selected = Buttons[0];
                }

                Line.Frame = new CGRect(Selected.X(), LineAlignment == TabBarLineAlignment.Bottom? this.Height() - LineHeight : 0, Selected.Width(), LineHeight);
            }
        }
コード例 #2
0
        public void Reload()
        {
            Container.RemoveConstraints(Container.Constraints);
            foreach (var v in Container.Subviews)
            {
                v.RemoveFromSuperview();
            }

            var format  = "V:|";
            var views   = new NSMutableDictionary();
            var metrics = new NSMutableDictionary();

            if (Toolbar != null)
            {
                metrics["toolbarTop"]    = NSNumber.FromNFloat(ToolbarEdgeInsets.Top);
                metrics["toolbarBottom"] = NSNumber.FromNFloat(ToolbarEdgeInsets.Bottom);

                format          += "-(toolbarTop)-[toolbar]-(toolbarBottom)";
                views["toolbar"] = Toolbar;
                Container.Layout(Toolbar).Horizontally(ToolbarEdgeInsets.Left, ToolbarEdgeInsets.Right);
            }

            if (ContentView != null)
            {
                metrics["contentViewBottom"] = NSNumber.FromNFloat(ContentViewEdgeInsets.Bottom);

                if (Toolbar != null)
                {
                    metrics["toolbarBottom"] = NSNumber.FromNFloat((metrics["toolbarBottom"] as NSNumber).NFloatValue + ContentViewEdgeInsets.Top);
                    format += "-[contentView]-(contentViewBottom)";
                }
                else
                {
                    metrics["contentViewTop"] = NSNumber.FromNFloat(ContentViewEdgeInsets.Top);
                    format += "-(contentViewTop)-[contentView]-(contentViewBottom)";
                }

                views["contentView"] = ContentView;
                Container.Layout(ContentView).Horizontally(ContentViewEdgeInsets.Left, ContentViewEdgeInsets.Right);

                ContentView.Grid().Reload();
                ContentView.Divider().Reload();
            }

            if (BottomBar != null)
            {
                metrics["bottomBarBottom"] = NSNumber.FromNFloat(BottomBarEdgeInsets.Bottom);

                if (ContentView != null)
                {
                    metrics["contentViewBottom"] = NSNumber.FromNFloat((metrics["contentViewBottom"] as NSNumber).FloatValue + BottomBarEdgeInsets.Top);
                    format += "-[bottomBar]-(bottomBarBottom)";
                }
                else if (Toolbar != null)
                {
                    metrics["toolbarBottom"] = NSNumber.FromNFloat((metrics["toolbarBottom"] as NSNumber).FloatValue + BottomBarEdgeInsets.Top);
                    format += "-[bottomBar]-(bottomBarBottom)";
                }
                else
                {
                    metrics["bottomBarTop"] = NSNumber.FromNFloat(BottomBarEdgeInsets.Top);
                    format += "-(bottomBarTop)-[bottomBar]-(bottomBarBottom)";
                }

                views["bottomBar"] = BottomBar;
                Container.Layout(BottomBar).Horizontally(BottomBarEdgeInsets.Left, BottomBarEdgeInsets.Right);
            }

            if (views.Count > 0)
            {
                Container.AddConstraints(Layout.Constraint(string.Format("{0}-|", format), 0, metrics, views));
            }

            //if (TitleLabel != null)
            //{
            //	verticalFormat += "-(insetTop)";
            //	metrics["insetTop"] = NSNumber.FromNFloat(ContentInset.Top + TitleLabelInset.Top);
            //}
            //else if (ContentView != null)
            //{
            //	verticalFormat += "-(insetTop)";
            //	metrics["insetTop"] = NSNumber.FromNFloat(ContentInset.Top + ContentViewEdgeInsets.Top);
            //}

            //if (TitleLabel != null)
            //{
            //	verticalFormat += "-[titleLabel]";
            //	views["titleLabel"] = TitleLabel;

            //	this.Layout(TitleLabel).Horizontally(left: ContentInset.Left + TitleLabelInset.Left, right: ContentInset.Right + TitleLabelInset.Right);
            //}

            //if (ContentView != null)
            //{
            //	if (TitleLabel == null)
            //	{
            //		metrics["insetTop"] = NSNumber.FromNFloat((metrics["insetTop"] as NSNumber).NFloatValue + ContentViewEdgeInsets.Top);
            //	}
            //	else
            //	{
            //		verticalFormat += "-(insetB)";
            //		metrics["insetB"] = NSNumber.FromNFloat(TitleLabelInset.Bottom + ContentViewEdgeInsets.Top);
            //	}
            //	verticalFormat += "-[contentView]";
            //	views["contentView"] = ContentView;

            //	this.Layout(ContentView).Horizontally(left: ContentInset.Left + ContentViewEdgeInsets.Left, right: ContentInset.Right + ContentViewEdgeInsets.Right);
            //}

            //if (LeftButtons != null && LeftButtons.Length > 0)
            //{
            //	var h = "H:|";
            //	var d = new NSMutableDictionary();
            //	var i = 0;
            //	foreach (var b in LeftButtons)
            //	{
            //		var k = String.Format("b{0}", i);
            //		d[k] = b;

            //		if (i == 0)
            //		{
            //			h += "-(left)-";
            //		}
            //		else
            //		{
            //			h += "-(left_right)-";
            //		}

            //		h += String.Format("[{0}]", k);

            //		this.Layout(b).Bottom(ContentInset.Bottom + LeftButtonsInset.Bottom);

            //		i += 1;
            //	}

            //	AddConstraints(Layout.Constraint(h, 0, NSDictionary.FromObjectsAndKeys(
            //		new object[] { ContentInset.Left + LeftButtonsInset.Left, LeftButtonsInset.Left + LeftButtonsInset.Right },
            //		new object[] { "left", "left_right" }
            //	), d));
            //}

            //if (RightButtons != null && RightButtons.Length > 0)
            //{
            //	var h = "H:|";
            //	var d = new NSMutableDictionary();
            //	var i = RightButtons.Length - 1;
            //	foreach (var b in LeftButtons)
            //	{
            //		var k = String.Format("b{0}", i);
            //		d[k] = b;

            //		if (i == 0)
            //		{
            //			h += "-(right)-";
            //		}
            //		else
            //		{
            //			h += "-(right_left)-";
            //		}

            //		h += String.Format("[{0}]", k);

            //		this.Layout(b).Bottom(ContentInset.Bottom + RightButtonsInset.Bottom);

            //		i -= 1;
            //	}

            //	AddConstraints(Layout.Constraint(h + "|", 0, NSDictionary.FromObjectsAndKeys(
            //		new object[] { ContentInset.Right + RightButtonsInset.Right, RightButtonsInset.Right + RightButtonsInset.Left },
            //		new object[] { "right", "right_left" }
            //	), d));
            //}

            //if (LeftButtons != null && LeftButtons.Length > 0)
            //{
            //	verticalFormat += "-(insetC)-[button]";
            //	views["button"] = LeftButtons[0];
            //	metrics["insetC"] = NSNumber.FromNFloat(LeftButtonsInset.Top);
            //	metrics["insetBottom"] = NSNumber.FromNFloat(ContentInset.Bottom + LeftButtonsInset.Bottom);
            //}
            //else if (RightButtons != null && RightButtons.Length > 0)
            //{
            //	verticalFormat += "-(insetC)-[button]";
            //	views["button"] = RightButtons[0];
            //	metrics["insetC"] = NSNumber.FromNFloat(RightButtonsInset.Top);
            //	metrics["insetBottom"] = NSNumber.FromNFloat(ContentInset.Bottom + RightButtonsInset.Bottom);
            //}

            //if (ContentView != null)
            //{
            //	if (metrics["insetC"] == null)
            //	{
            //		metrics["insetBottom"] = NSNumber.FromNFloat(ContentInset.Bottom + ContentViewEdgeInsets.Bottom + (Divider ? DividerInset.Top + DividerInset.Bottom : 0));
            //	}
            //	else
            //	{
            //		metrics["insetC"] = NSNumber.FromNFloat((metrics["insetC"] as NSNumber).NFloatValue + ContentViewEdgeInsets.Bottom + (Divider ? DividerInset.Top + DividerInset.Bottom : 0));
            //	}
            //}
            //else if (TitleLabel != null)
            //{
            //	if (metrics["insetC"] == null)
            //	{
            //		metrics["insetBottom"] = NSNumber.FromNFloat(ContentInset.Bottom + TitleLabelInset.Bottom + (Divider ? DividerInset.Top + DividerInset.Bottom : 0));
            //	}
            //	else
            //	{
            //		metrics["insetC"] = NSNumber.FromNFloat((metrics["insetC"] as NSNumber).NFloatValue + TitleLabelInset.Bottom + (Divider ? DividerInset.Top + DividerInset.Bottom : 0));
            //	}
            //}
            //else if (metrics["insetC"] != null)
            //{
            //	metrics["insetC"] = NSNumber.FromNFloat((metrics["insetC"] as NSNumber).NFloatValue + ContentInset.Bottom + (Divider ? DividerInset.Top + DividerInset.Bottom : 0));
            //}

            //if (views.Count > 0)
            //{
            //	verticalFormat += "-(insetBottom)-|";

            //	AddConstraints(Layout.Constraint(verticalFormat, 0, metrics, views));
            //}
        }
コード例 #3
0
        public virtual void Reload()
        {
            var lc      = 0;
            var rc      = 0;
            var l       = LeftViews.Count * InterimSpace;
            var r       = RightViews.Count * InterimSpace;
            var p       = this.Width() - l - r - ContentEdgeInsets.Left - ContentEdgeInsets.Right;
            var columns = (int)System.NMath.Ceiling(p / GridFactor);

            this.Grid().Begin();
            this.Grid().Views.Clear();
            this.Grid().Axis.Columns = columns;

            foreach (var v in LeftViews)
            {
                if (v is UIButton)
                {
                    (v as UIButton).ContentEdgeInsets = UIEdgeInsets.Zero;
                    (v as UIButton).TitleEdgeInsets   = UIEdgeInsets.Zero;
                }

                v.SetWidth(v.IntrinsicContentSize.Width);
                v.SizeToFit();
                v.Grid().Columns = ((int)NMath.Ceiling(v.Width() / GridFactor)) + 2;

                lc += v.Grid().Columns;

                this.Grid().Views.Add(v);
            }

            this.Grid().Views.Add(ContentView);

            foreach (var v in RightViews)
            {
                if (v is UIButton)
                {
                    (v as UIButton).ContentEdgeInsets = UIEdgeInsets.Zero;
                    (v as UIButton).TitleEdgeInsets   = UIEdgeInsets.Zero;
                }

                v.SetWidth(v.IntrinsicContentSize.Width);
                v.SizeToFit();
                v.Grid().Columns = ((int)NMath.Ceiling(v.Width() / GridFactor)) + 2;

                rc += v.Grid().Columns;

                this.Grid().Views.Add(v);
            }

            ContentView.Grid().Begin();
            ContentView.Grid().Views = CenterViews;

            if (ContentViewAlignment == ContentViewAlignment.Center)
            {
                if (lc < rc)
                {
                    ContentView.Grid().Columns = columns - 2 * rc;
                    ContentView.Grid().Offset.Columns = rc - lc;
                }
                else
                {
                    ContentView.Grid().Columns = columns - 2 * lc;
                    ContentView.Grid().Offset.Columns = 0;
                    if (RightViews[0] != null)
                    {
                        RightViews[0].Grid().Offset.Columns = lc - rc;
                    }
                }
            }
            else
            {
                ContentView.Grid().Columns = columns - lc - rc;
            }

            this.Grid().Commit();
            ContentView.Grid().Commit();
        }