【问题标题】:Xamarin Forms IOS Navigation BarXamarin Forms IOS导航栏
【发布时间】:2021-10-19 12:21:40
【问题描述】:

在 Xamarin Forms IOS 上需要帮助(Android 工作正常)。当我在一个选项卡式项目上打开一个新页面时,IOS上的导航栏出现INVISIBLE,但是上下滚动页面时,导航栏出现了,虽然不可见,但是后退按钮在那里并且可以点击。项目的所有其他页面都有相同的行为,后退按钮在那里,但不可见。见下图。 如何设置导航栏对所有页面可见?

在此处查看 GIF:

【问题讨论】:

    标签: ios forms xamarin navbar


    【解决方案1】:

    这是iOS15的默认行为更改,为了解决这个问题我们只需要修改UINavigationBarAppearance scrollEdgeAppearance属性。

    将以下代码放入iOS项目中的AppDelegate.csSceneDelegate.cs中。

    UINavigationBarAppearance a = new UINavigationBarAppearance();
    a.ConfigureWithTransparentBackground();
    a.BackgroundColor = UIColor.Blue;
    a.TitleTextAttributes = new UIStringAttributes() { ForegroundColor = UIColor.White};
    
    
    UINavigationBar.Appearance.StandardAppearance = a;
    UINavigationBar.Appearance.CompactAppearance = a;
    UINavigationBar.Appearance.ScrollEdgeAppearance = a;
    

    参考

    https://developer.apple.com/forums/thread/684454.

    【讨论】:

    • 非常感谢。
    • 如果问题已经解决,请考虑将其标记为答案,以帮助面临相同问题的其他人。
    • 嗨 Colex,我是 stackoverflow 的新手。如何标记答案?我也有同样的问题,当内容向上滚动时,标签栏变得透明。
    • 谢谢,仍然不知道为什么对这些东西进行编程很困难(我只是想要导航栏的背景颜色?)但这很有帮助!另外,如果您想在 xamarin 中使用自定义颜色,则可以执行以下操作: Color.FromHex("#[hex color]").ToUIColor();