【问题标题】:Xamarin.Forms on IOS: Remove space between SearchBar and NavigationBarIOS 上的 Xamarin.Forms:删除 SearchBar 和 NavigationBar 之间的空间
【发布时间】:2018-07-25 21:45:13
【问题描述】:

在我的页面中,我在 ListView 上方添加了一个 SearchBar。它工作得很好,但我看到 NavigationBar 和 SearchBar 之间有一条小线。任何人都知道如何删除它? 谢谢

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

【问题讨论】:

    标签: ios xamarin uisearchbar searchbar


    【解决方案1】:

    要移除底部阴影线,您可以使用自定义渲染器。这将完全满足您的需求。

    [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 ();
            }
        }
    }
    

    欲了解更多信息,您可以访问this

    【讨论】:

    • 谢谢。我搜索错了。我认为这与 SearchBar 有关。