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

Toolbar.bottomBar不显示内容且遮挡列表问题求助

解决方案

问题1:底部Toolbar按钮不可见

按钮不可见大概率是按钮文字颜色与底部Toolbar背景色一致导致的适配问题,可按以下方式修复:

显式设置按钮颜色

给按钮添加明确的文字颜色,确保编辑模式下能正常显示:

.toolbar {
    if editMode?.wrappedValue.isEditing == true {
        ToolbarItemGroup(placement: .bottomBar) {
            Button("Select All", role: .none) {
                selectAll()
            }
            .foregroundColor(.blue)
            Button("Deselect All", role: .none) {
                deSelectAll()
            }
            .foregroundColor(.blue)
        }
    }
    ToolbarItemGroup(placement: .navigationBarTrailing) {
        EditButton()
    }
}

另外要确认视图顶部已正确声明环境变量:

@Environment(\.editMode) private var editMode

缺少这行代码会导致editMode判断失效,底部Toolbar可能无法正常触发显示。

问题2:底部Toolbar遮挡列表最后一项

默认.bottomBar不会自动调整列表布局,推荐改用**safeAreaInset**替代,系统会自动给列表添加底部内边距,彻底避免遮挡:

// 替换原toolbar的底部栏部分
.safeAreaInset(edge: .bottom) {
    if editMode?.wrappedValue.isEditing == true {
        HStack {
            Button("Select All", role: .none) {
                selectAll()
            }
            .foregroundColor(.blue)
            Spacer()
            Button("Deselect All", role: .none) {
                deSelectAll()
            }
            .foregroundColor(.blue)
        }
        .padding()
        .background(Color(.systemBackground))
        .border(Color(.separator), edge: .top) // 可选:添加上部分割线区分
    }
}
// 保留导航栏的编辑按钮
.toolbar {
    ToolbarItemGroup(placement: .navigationBarTrailing) {
        EditButton()
    }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 19:54:56