private static NSAttributedString CreateTitleString(StyledNavigationBarPage page) { if (page == null) { return(null); } bool hasSubTitle = !string.IsNullOrEmpty(page.Subtitle); var font = hasSubTitle ? page.TitleFont : page.TitleOnlyFont; var titleAttributedString = font.BuildAttributedString(!String.IsNullOrWhiteSpace(page.Title) ? page.Title : ""); return(titleAttributedString); }
private static UIView BuildSubTitleView(StyledNavigationBarPage page) { bool hasSubTitle = !string.IsNullOrEmpty(page.Subtitle); var titleLabel = new UILabel(new CoreGraphics.CGRect(0, 0, 0, 0)); titleLabel.Tag = 100; var titleAttributedString = CreateTitleString(page); titleLabel.AdjustsFontSizeToFitWidth = true; titleLabel.AttributedText = titleAttributedString; titleLabel.SizeToFit(); if (hasSubTitle) { var subtitleLabel = new UILabel(new CoreGraphics.CGRect(0, titleLabel.Frame.Height, 0, 0)); subtitleLabel.Tag = 200; var subTitleAttributedString = page.SubtitleFont.BuildAttributedString(page.Subtitle); subtitleLabel.AttributedText = subTitleAttributedString; subtitleLabel.SizeToFit(); var view = new UIView(new CoreGraphics.CGRect(0, 0, Math.Max(titleLabel.Frame.Width, subtitleLabel.Frame.Width), titleLabel.Frame.Height + subtitleLabel.Frame.Height)); // Center title or subtitle on screen (depending on which is larger) if (titleLabel.Frame.Width >= subtitleLabel.Frame.Width) { var adjustment = subtitleLabel.Frame; adjustment.Location = new CoreGraphics.CGPoint(view.Frame.Left + view.Frame.Width / 2 - subtitleLabel.Frame.Width / 2, adjustment.Top); subtitleLabel.Frame = adjustment; } else { var adjustment = titleLabel.Frame; adjustment.Location = new CoreGraphics.CGPoint(view.Frame.Left + view.Frame.Width / 2 - titleLabel.Frame.Width / 2, adjustment.Top); titleLabel.Frame = adjustment; } view.Add(titleLabel); view.Add(subtitleLabel); return(view); } else { return(titleLabel); } }