使用 SwiftUI 更改菜单的宽度

Change the width of a Menu using SwiftUI

提问人:baohoang 提问时间:6/19/2023 更新时间:6/19/2023 访问量:194

问:

有人告诉我如何使用 SwiftUI 更改菜单的宽度吗?

我尝试使用但没有改变。ViewModifier

这是我的代码:

struct ContentView: View {
    
    var body: some View {
        VStack {
            Menu("Options") {
                Button("Option 1") {
                }
                Button("Option 2") {
                }
            }
            .modifier(
                MenuWidthModifier(width: 50)
            )
        }
    }
}

struct MenuWidthModifier: ViewModifier {
    let width: CGFloat
    
    func body(content: Content) -> some View {
        content
            .frame(width: width)
    }
}
迅捷 SwiftUI

评论


答: 暂无答案