Search code examples
iosxamarinuisearchbarsearchbar

Xamarin.Forms on IOS: Remove space between SearchBar and NavigationBar


in my page, i added a SearchBar above a ListView. It works good but i see a small line between the NavigationBar and the SearchBar. Anyone knows how to remove it? Thanks

    <StackLayout Orientation="Vertical">
    <SearchBar 
        CancelButtonColor="White"
        BackgroundColor="{x:Static local:Consts.PrimaryColor}"
        IsVisible="{Binding IsSearchVisible, Mode=OneWay}"
    />
    <ListView

Space between navigation bar and search bar


Solution

  • To remove bottom shadow line you can use custom renderer. That going to do exactly what you need.

    [assembly: ExportRenderer(typeof(NavigationPage), typeof(NoLineNavigationRenderer))] 
    namespace MyMobileProject.iOS {
        public class NoLineNavigationRenderer : NavigationRenderer {
    
            public override void ViewDidLoad(){
                base.ViewDidLoad();
                // remove lower border and shadow of the navigation bar
                NavigationBar.SetBackgroundImage(new UIImage(), UIBarMetrics.Default);
                NavigationBar.ShadowImage = new UIImage ();
            }
        }
    }
    

    For more information you can visit this