public bool ShouldPushItem(UINavigationBar navigationBar, UINavigationItem item) { var v = navigationBar as NavigationBar; if (v != null) { item.BackButton().AddTarget(this, new Selector("handleBackButton"), UIControlEvent.TouchUpInside); item.BackButton().Image = v.BackButtonImage; var c = item.LeftViews(); if (c != null) { c.Add(item.BackButton()); item.SetLeftViews(c); } else { item.SetLeftViews(new List <UIView> { item.BackButton() }); } v.layoutNavigationItem(item); } return(true); }
/** * Lays out the UINavigationItem. * - Parameter item: A UINavigationItem to layout. */ internal void layoutNavigationItem(UINavigationItem item) { if (WillLayout) { prepareItem(item); prepareTitleView(item); var frame = item.TitleView.Frame; frame.Location = CGPoint.Empty; frame.Size = IntrinsicContentSize; item.TitleView.Frame = frame; var lc = 0; var rc = 0; var l = ((nfloat)(item.LeftViews().Count) * InterimSpace); var r = ((nfloat)(item.RightViews().Count) * InterimSpace); var p = this.Width() - l - r - ContentEdgeInsets.Left - ContentEdgeInsets.Right; var columns = (int)(NMath.Ceiling(p / GridFactor)); item.TitleView.Grid().Begin(); item.TitleView.Grid().Views.Clear(); item.TitleView.Grid().Axis.Columns = columns; foreach (var v in item.LeftViews()) { if (v is UIButton) { ((UIButton)v).ContentEdgeInsets = UIEdgeInsets.Zero; ((UIButton)v).TitleEdgeInsets = UIEdgeInsets.Zero; } v.SetWidth(v.IntrinsicContentSize.Width); v.SizeToFit(); v.Grid().Columns = ((int)NMath.Ceiling(v.Width() / GridFactor)) + 2; lc += v.Grid().Columns; item.TitleView.Grid().Views.Add(v); } item.TitleView.Grid().Views.Add(item.ContentView()); foreach (var v in item.RightViews()) { if (v is UIButton) { ((UIButton)v).ContentEdgeInsets = UIEdgeInsets.Zero; ((UIButton)v).TitleEdgeInsets = UIEdgeInsets.Zero; } v.SetWidth(v.IntrinsicContentSize.Width); v.SizeToFit(); v.Grid().Columns = ((int)NMath.Ceiling(v.Width() / GridFactor)) + 2; rc += v.Grid().Columns; item.TitleView.Grid().Views.Add(v); } item.ContentView().Grid().Begin(); if (item.ContentViewAlignment() == ContentViewAlignment.Center) { if (lc < rc) { item.ContentView().Grid().Columns = columns - 2 * rc; item.ContentView().Grid().Offset.Columns = rc - lc; } else { item.ContentView().Grid().Columns = columns - 2 * lc; item.ContentView().Grid().Offset.Columns = 0; if (item.RightViews().Count > 0) { item.RightViews()[0].Grid().Offset.Columns = lc - rc; } } } else { item.ContentView().Grid().Columns = columns - lc - rc; } item.TitleView.Grid().InterimSpace = InterimSpace; item.TitleView.Grid().ContentEdgeInsets = ContentEdgeInsets; item.TitleView.Grid().Commit(); item.ContentView().Grid().Commit(); // contentView alignment. if (!string.IsNullOrEmpty(item.Title())) { if (item.Titlelabel().Superview == null) { item.ContentView().AddSubview(item.Titlelabel()); } item.Titlelabel().Frame = item.ContentView().Bounds; } else { item.Titlelabel().RemoveFromSuperview(); } if (!string.IsNullOrEmpty(item.Detail())) { if (item.DetailLabel().Superview == null) { item.ContentView().AddSubview(item.DetailLabel()); } if (item.Titlelabel().Superview == null) { item.DetailLabel().Frame = item.ContentView().Bounds; } else { item.Titlelabel().SizeToFit(); item.DetailLabel().SizeToFit(); nfloat diff = (item.ContentView().Frame.Height - item.Titlelabel().Frame.Height - item.DetailLabel().Frame.Height) / 2; item.Titlelabel().SetHeight(item.Titlelabel().Height() + diff); item.Titlelabel().SetWidth(item.ContentView().Width()); item.DetailLabel().SetHeight(item.DetailLabel().Height() + diff); item.DetailLabel().SetWidth(item.ContentView().Width()); item.DetailLabel().SetY(item.Titlelabel().Height()); } } else { item.DetailLabel().RemoveFromSuperview(); } } }