Skip to content

Instantly share code, notes, and snippets.

@rdelrosario
Created December 6, 2017 01:09
Show Gist options
  • Select an option

  • Save rdelrosario/9dcaf9dd9a1ab2d5984b3edd7be80634 to your computer and use it in GitHub Desktop.

Select an option

Save rdelrosario/9dcaf9dd9a1ab2d5984b3edd7be80634 to your computer and use it in GitHub Desktop.
iOS Setup NavBar
void SetupNavBar(CGSize size)
{
if (NavigationController != null && titleView != null)
{
var page = Element as Page;
containerView.Frame = new CGRect(0, 0, size.Width, size.Height);
titleView.Layer.BorderWidth = CustomNavigationPage.GetTitleBorderWidth(Element);
titleView.Layer.CornerRadius = CustomNavigationPage.GetTitleBorderCornerRadius(Element);
titleView.Layer.BorderColor = CustomNavigationPage.GetTitleBorderColor(Element)?.ToCGColor() ?? UIColor.Clear.CGColor;
SetupTextFont(titleLabel, CustomNavigationPage.GetTitleFont(page), CustomNavigationPage.GetTitleColor(page));
SetupBackground();
if (!string.IsNullOrEmpty(CustomNavigationPage.GetTitleBackground(Element)))
{
try
{
var image = UIImage.FromBundle(CustomNavigationPage.GetTitleBackground(Element));
titleView.Frame = new CGRect(titleView.Frame.X, titleView.Frame.Y, titleView.Frame.Width == 0?Math.Min(size.Width,image.Size.Width): Math.Min(titleView.Frame.Width, image.Size.Width), titleView.Frame.Height == 0 ? Math.Min(size.Height, image.Size.Height) : Math.Min(titleView.Frame.Height, image.Size.Height));
titleView.BackgroundColor = UIColor.FromPatternImage(image);
}
catch (Exception ex)
{
titleView.BackgroundColor = CustomNavigationPage.GetTitleFillColor(Element)?.ToUIColor() ?? UIColor.Clear;
}
}
else
{
titleView.BackgroundColor = CustomNavigationPage.GetTitleFillColor(Element)?.ToUIColor() ?? UIColor.Clear;
}
ParentViewController.NavigationItem.TitleView = containerView;
ParentViewController.NavigationItem.TitleView.SetNeedsDisplay();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment