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

如何移除SwiftUI ToolbarItem菜单中的向下箭头

移除SwiftUI Toolbar中Menu组件的默认向下箭头

方法一:iOS 16+ 原生API(推荐)

从iOS 16开始,SwiftUI为Menu提供了专门隐藏箭头的修饰符,直接添加即可生效:

.toolbar {
    ToolbarItem(placement: .primaryAction) {
        Menu {
            Button(action: {}) {
                Label("Create a file", systemImage: "doc")
            }
            Button(action: {}) {
                Label("Create a folder", systemImage: "folder")
            }
        } label: {
            Label("Share", systemImage: "square.and.arrow.up")
        }
        .menuIndicator(.hidden) // 关键代码:隐藏默认箭头
    }
}

方法二:iOS 15及以下兼容方案

如果需要适配iOS 15或更早版本,可通过自定义按钮+弹出层的方式模拟Menu效果,彻底避开默认箭头:

// 视图内添加状态变量
@State private var isMenuPresented = false

// Toolbar部分代码
.toolbar {
    ToolbarItem(placement: .primaryAction) {
        Button {
            withAnimation {
                isMenuPresented.toggle()
            }
        } label: {
            Label("Share", systemImage: "square.and.arrow.up")
        }
        .popover(isPresented: $isMenuPresented, arrowEdge: .top) {
            VStack(spacing: 0) {
                Button(action: {
                    isMenuPresented = false
                }) {
                    Label("Create a file", systemImage: "doc")
                        .frame(minWidth: 180, alignment: .leading)
                        .padding()
                }
                Button(action: {
                    isMenuPresented = false
                }) {
                    Label("Create a folder", systemImage: "folder")
                        .frame(minWidth: 180, alignment: .leading)
                        .padding()
                }
            }
            .background(Color(.systemBackground))
            .cornerRadius(12)
        }
    }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 12:21:26