首页 > 解决方案 > SwiftUI macOS MenuButton 标签问题

问题描述

我在我的 macOS 应用程序中使用 MenuButton。MenuButton 将标签和内容作为参数,效果很好。苹果给出以下声明

struct MenuButton<Label, Content> where Label : View, Content : View

我正在尝试使用带有两个Image和一个文本作为标签的视图,如下所示:

MenuButton(label: Title(name: "Title"), content: {
    ...
})
.menuButtonStyle(BorderlessButtonMenuButtonStyle())

标题声明如下:

struct Title: View {
    var name : String = ""
    
    var body: some View {
        HStack
        {
            Text(self.name)
                .foregroundColor(Color("c_SecondaryColor"))
            
            Image("PickerIcon") //<< This is visible

            Image("PickerIcon2") //<< This is NOT visible - can not use two Image

        }
    }
}

在标题中我有两个图像。但是,只显示了一个。为什么标签只允许一个图像,即使它被声明为View类型。

标签: macosswiftui

解决方案


推荐阅读