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

SwiftUI中如何修改TabView默认的“More”标签为自定义文字

结论

SwiftUI 中 TabView 超过5个标签时自动生成的「More」标签文字支持自定义修改。由于SwiftUI的TabView本质是对UIKit中UITabBarController的封装,目前没有暴露纯SwiftUI的原生修改接口,需要通过UIKit的运行时、Appearance特性实现调整。

实现方法

方法1:全局配置(接入最简单)

在App入口的初始化方法中配置全局UITabBarItem样式,会对App内所有TabView的More标签生效:

@main
struct YourApp: App {
    init() {
        // 自定义More标签文字,可替换为你需要的文案
        let moreItemAppearance = UITabBarItem.appearance(whenContainedInInstancesOf: [UITabBarController.self])
        moreItemAppearance.title = "你的自定义文案"
        // 如果需要同时自定义More标签图标,可添加下面代码
        // moreItemAppearance.image = UIImage(systemName: "ellipsis.circle")
    }
    var body: some Scene {
        WindowGroup {
            // 你的入口视图,包含原有TabView代码
            ContentView()
        }
    }
}

原有TabView的代码不需要做任何修改,保持你之前写的tabItem配置、accentColor设置即可。

方法2:单TabView定制(不影响全局)

如果只需要修改某一个特定TabView的More标签,不希望全局生效,可以给TabView添加onAppear修饰符,在页面出现时拿到当前的TabBarController实例修改对应属性:

var body: some View {
    TabView(selection: $handler) {
        // 原有所有子视图、tabItem配置完全保留
        InicioView()
            .tabItem {
                Label("Inicio", systemImage: "house.circle")
                    .font(.system(size: 32))
                    .foregroundColor(Color("verde"))
            }.tag(0)

        TarjetaRodelagView()
            .tabItem {
                Label("Tarjeta Rodelag", systemImage: "creditcard.circle")
                    .font(.system(size: 32))
                    .foregroundColor(Color("verde"))
            }.tag(2)

        CategoriasView()
            .tabItem {
                Label("Categorías", systemImage: "list.bullet.rectangle.fill")
                    .font(.system(size: 32))
                    .foregroundColor(Color("verde"))
            }.tag(1)

        InicioView()
            .tabItem {
                VStack {
                    Image("ari").resizable().frame(width: 55, height: 55).scaledToFit()
                    Text("ARI")
                }
            }.tag(4)

        SucursalesView()
            .tabItem {
                Label("Sucursales", systemImage: "map")
                    .font(.system(size: 32))
                    .foregroundColor(Color("verde"))
            }.tag(3)

        CatalogoView()
            .tabItem {
                Label("Catálogo", systemImage: "book.circle")
                    .font(.system(size: 32))
                    .foregroundColor(Color("verde"))
            }.tag(6)
    }
    .accentColor(Color("verde"))
    .onAppear {
        // 查找当前激活窗口下的UITabBarController实例
        guard let windowScene = UIApplication.shared.connectedScenes
            .first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene,
              let tabBarController = windowScene.windows
            .first(where: \.isKeyWindow)?
            .rootViewController as? UITabBarController else { return }
        // 修改当前TabView的More标签文字
        tabBarController.moreNavigationController.tabBarItem.title = "你的自定义文案"
        // 如需自定义More标签图标,解开下方注释即可
        // tabBarController.moreNavigationController.tabBarItem.image = UIImage(systemName: "自定义图标名")
        // 如需修改点击More后进入页面的导航栏标题,添加下方代码
        // tabBarController.moreNavigationController.topViewController?.title = "自定义更多页标题"
    }
}
注意事项
  • 不要手动新增tabItem来模拟替换系统More标签,系统生成的More标签自带标签编辑、排序功能,手动实现会破坏原有交互逻辑。
  • 上述两种方案兼容iOS15及以上所有系统版本,不会影响原有TabView的选中态、图标颜色等配置。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.28 08:15:45