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

macOS SwiftUI中用Menu替代MenuButton时隐藏下拉箭头的方法

在macOS SwiftUI中使用Menu组件隐藏下拉箭头

方法一:适用于macOS 13+(Ventura及以上)

直接使用.menuIndicator(.hidden)修饰符即可隐藏默认的下拉箭头,这是官方提供的最简洁方案:

Menu("☰") {
    Button(action: { print("Something") }) {
        HStack {
            Image(systemName: "questionmark.circle")
            Text("Something")
        }
    }
    Button(action: { print("Something Else") }) {
        HStack {
            Image(systemName: "exclamationmark.circle")
            Text("Something Else")
        }
    }
}
.menuIndicator(.hidden)

方法二:兼容macOS 12及更早版本

通过自定义Menu的标签视图,完全控制显示内容,避免默认箭头出现。同时可以搭配按钮样式实现无边界的点击效果:

Menu {
    Button(action: { print("Something") }) {
        HStack {
            Image(systemName: "questionmark.circle")
            Text("Something")
        }
    }
    Button(action: { print("Something Else") }) {
        HStack {
            Image(systemName: "exclamationmark.circle")
            Text("Something Else")
        }
    }
} label: {
    Text("☰")
        .padding(4) // 优化点击热区大小
}
.buttonStyle(BorderlessButtonStyle())

这两种方式都能实现原MenuButton搭配BorderlessButtonMenuButtonStyle时仅显示图标、无下拉箭头的效果。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 08:14:59