【问题标题】:SwiftUI Menu Picker Navigation Bar show only iconSwiftUI 菜单选择器导航栏仅显示图标
【发布时间】:2021-11-23 11:03:34
【问题描述】:

我想在导航栏上有一个菜单选择器,到目前为止,我可以使用以下代码完成该操作

.toolbar {
    ToolbarItem(placement: ToolbarItemPlacement.navigationBarTrailing, content: {
        Picker(selection: $requestHistoryFilter, content: {
            ForEach(SongRequestsContainer.SongHistoryFilter.allCases, id: \.self) {
                Text($0.displayText())
            }
        }, label: {
            Image(systemName: "line.horizontal.3.decrease.circle")
        })                          
})

但是上面的代码总是在导航栏上输出选择选项的文本,我想要的是总是显示标签,有没有办法做到这一点?

在这种情况下,我想始终显示图像。

有没有办法做到这一点?

【问题讨论】:

  • 尝试在此处使用菜单而不是选择器。

标签: xcode swiftui ios14


【解决方案1】:

按照@hayesk 的建议,使用菜单进行包装是可行的方法

这对我有用,可以作为其他人的参考

.toolbar {
    ToolbarItem(placement: ToolbarItemPlacement.navigationBarTrailing, content: {
        Menu(content: {
            Picker(selection: $requestHistoryFilter, label: Image(systemName: "line.horizontal.3.decrease.circle")) {
                ForEach(VideoRequestsContainer.VideoHistoryFilter.allCases, id: \.self) {
                    Text($0.displayText())
                }
            }
        }, label: {
            Image(systemName: "line.horizontal.3.decrease.circle")
        })
     })
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-07
    • 1970-01-01
    • 1970-01-01
    • 2020-11-06
    • 2015-07-05
    • 1970-01-01
    相关资源
    最近更新 更多