Search code examples
xamarin.formsuinavigationbarios11

iOS 11 large titles in Xamarin.Forms


How do I enable iOS 11 prefersLargeTitles throughout my Xamarin.Forms app?

I tried creating a custom renderer derived from PageRenderer for NavigationPage, setting:

ViewController.NavigationController.NavigationBar.PrefersLargeTitles = true;

This didn't have any effect, however.


Solution

  • Voila

    [assembly: ExportRenderer(typeof(NavigationPage), typeof(NavBarRenderer))]
    namespace LargeTitleSample.iOS
    {
        public class NavBarRenderer : NavigationRenderer
        {
            protected override void OnElementChanged(Xamarin.Forms.Platform.iOS.VisualElementChangedEventArgs e)
            {
                base.OnElementChanged(e);
    
                NavigationBar.PrefersLargeTitles = true;
            }
        }
    }
    

    You have to create a custom renderer for the NavigationPage inheriting the NavigationRenderer. Then set the PrefersLargeTitles property on the NavigationBar to true.

    It seems that when you add some scrollable control to the page, it will automatically have to 'big to small' effect when scrolling up, at least for a ListView.

    Working example repo is here: https://github.com/jfversluis/LargeTitleSample