如何移除SwiftUI ToolbarItem菜单中的向下箭头
方法一: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
相关产品推荐
相关产品推荐

