You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET MAUI iOS 18定义Shell.TitleView后仍显示标题问题

iOS 18中Shell.TitleView无法隐藏ShellContent.Title的问题解决

我在AppShell.xaml中用Shell.TitleView自定义导航栏,替代默认的Shell.Title,这套逻辑在iOS 17.5上运行正常,但到了iOS 18的模拟器和真机里出问题了——ShellContent设置的Title还是会显示出来。

相关代码

ShellContent代码

<ShellContent
 Title="HIDE ME"
 ContentTemplate="{DataTemplate local:AttendPage}"
 Route="AttendPage" />

Shell.TitleView代码

<Shell.TitleView>
 <HorizontalStackLayout VerticalOptions="Fill">
     <ImageButton
         x:Name="TButton"
         Source="back.png"
         Aspect="Center"
         Clicked="TButton_Clicked" />

     <Label 
         x:Name="myTitleView"
         Text=""
         VerticalOptions="Center"
         VerticalTextAlignment="Center"
         BackgroundColor="White"
         TextColor="Black"
         FontAttributes="Bold"
         FontSize="Medium">  
     </Label>
 </HorizontalStackLayout>
</Shell.TitleView>

问题截图

iOS 18异常:ShellContent的Title仍显示


解决方法

1. 直接清空ShellContent的Title

把ShellContent的Title设为空字符串,替代原来的"HIDE ME":

<ShellContent
 Title=""
 ContentTemplate="{DataTemplate local:AttendPage}"
 Route="AttendPage" />

如果后续需要用到这个Title,可以在代码后台动态赋值,不要在XAML里硬写。

2. 平台层面强制隐藏默认标题(iOS专属)

如果上面的方法不生效,可以在iOS项目里写个自定义Shell渲染器,直接替换导航栏的默认标题视图:

using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(AppShell), typeof(YourApp.iOS.CustomShellRenderer))]
namespace YourApp.iOS
{
    public class CustomShellRenderer : ShellRenderer
    {
        protected override IShellSectionRenderer CreateShellSectionRenderer(ShellSection shellSection)
        {
            var renderer = base.CreateShellSectionRenderer(shellSection);
            if (renderer is ShellSectionRenderer sectionRenderer)
            {
                // 用空视图覆盖默认标题
                sectionRenderer.NavigationBar.TopItem.TitleView = new UIView();
            }
            return renderer;
        }
    }
}

这个方法从iOS原生层面处理,能确保自定义TitleView完全替代默认标题。

3. 检查并更新框架版本

如果用的是.NET MAUI,这个问题大概率是iOS 18的适配bug,去看看有没有最新的MAUI版本,微软可能已经修复了这个兼容性问题。


内容的提问来源于stack exchange,提问作者Ben Levy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 22:02:43