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

iOS 16与Catalyst中UIMenu/UIAction图标不显示问题

解决UIContextMenu图标不显示的问题

你遇到的图标不显示问题,根源在于给UIMenu设置了displayInline选项——在iOS 16和Catalyst环境下,这个选项会强制菜单以内联模式展示,系统会自动隐藏所有图标(包括主菜单标题图标和子项UIAction的图标),和UIImage的解包方式无关。

解决方案

移除UIMenu.Options.displayInline选项即可恢复图标显示:

修改后的代码:

extension CapoButton: UIContextMenuInteractionDelegate {
    func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
        return UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { _ in
            return UIMenu(title: "test", 
                          image: UIImage(systemName: "star.fill"), 
                          identifier: .capoButtonMenu,
                          children: [
                UIAction(title: "subtest 1", image: UIImage(systemName: "star.circle")) {_ in
                    print("fred 1")
                },
                UIAction(title: "subtest 2", image: UIImage(systemName: "star")) {_ in
                    print("fred 2")
                }
            ])
        }
    }
}

补充说明

如果必须保留displayInline的样式(比如菜单紧凑展示),系统默认就不会显示图标——这是Apple对该菜单样式的设计规范。如果需要带图标的紧凑菜单,可能需要自定义菜单视图来实现。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 18:18:19