macos - Style a plain dropdown menu in SwiftUI - Stack Overflow

I’m trying to create a simple dropdown button in SwiftUI on macOS. Normally I would expect to use somet

I’m trying to create a simple dropdown button in SwiftUI on macOS. Normally I would expect to use something like this:

MenuButton("☰") {
    Button(action: { print("Something") }) {
        HStack {
            Image(systemName: "questionmark.circle")
            Text("Something")
        }
    }
    Button(action: { print("Something Else") }) {
        HStack {
            Image(systemName: "exclamationmark.circle")
            Text("Something Else")
        }
    }
}
.menuButtonStyle(BorderlessButtonMenuButtonStyle())

The .menuButtonStyle(BorderlessButtonMenuButtonStyle()) shows only the menu icon (☰)

without the drop down

However, MenuButton has been deprecated in favour of Menu, which is fine, but I then need to modify it with .menuStyle, and can’t find the equivalent of BorderlessButtonMenuButtonStyle

What would be the equivalent for Menu to suppress the drop down arrow?

I’m trying to create a simple dropdown button in SwiftUI on macOS. Normally I would expect to use something like this:

MenuButton("☰") {
    Button(action: { print("Something") }) {
        HStack {
            Image(systemName: "questionmark.circle")
            Text("Something")
        }
    }
    Button(action: { print("Something Else") }) {
        HStack {
            Image(systemName: "exclamationmark.circle")
            Text("Something Else")
        }
    }
}
.menuButtonStyle(BorderlessButtonMenuButtonStyle())

The .menuButtonStyle(BorderlessButtonMenuButtonStyle()) shows only the menu icon (☰)

without the drop down

However, MenuButton has been deprecated in favour of Menu, which is fine, but I then need to modify it with .menuStyle, and can’t find the equivalent of BorderlessButtonMenuButtonStyle

What would be the equivalent for Menu to suppress the drop down arrow?

Share Improve this question asked Nov 17, 2024 at 5:09 ManngoManngo 16.6k13 gold badges104 silver badges148 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

As per the documentation (which may be somewhat innacurate since .buttonStyle(.borderless) does display a down arrow):

borderlessButton Deprecated

Use menuStyle(_:) with button and buttonStyle(_:) with borderless.

        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")
                    }
                }
            }
            .menuStyle(.button)
            .buttonStyle(.plain)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745637887a4637506.html

相关推荐

  • macos - Style a plain dropdown menu in SwiftUI - Stack Overflow

    I’m trying to create a simple dropdown button in SwiftUI on macOS. Normally I would expect to use somet

    22天前
    70

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信