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

如何在长按显示ContextMenu时更改内容的背景颜色?

ContextMenu显示时背景切换示例

ContextMenu显示时背景切换效果

这是ChatGPT在ContextMenu显示时,消息内容从透明背景切换为深灰色背景的示例。以下是实现代码:

struct ContentView: View {
    var body: some View {
        Text("Long press for menu")
            .background(.clear)
            .contextMenu {
                Button {
                    print("Pills selected")
                } label: {
                    Label("Pills", systemImage: "pills")
                }

                Button {
                    print("Heart selected")
                } label: {
                    Label("Heart rate", systemImage: "heart")
                }

                Button {
                    print("ECG selected")
                } label: {
                    Label("ECG", systemImage: "waveform.path.ecg")
                }
            }
    }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 14:37:09