简体   繁体   English

如何从 SwiftUI 中的 actionSheet 中删除标题

[英]How to remove title from actionSheet in SwiftUI

Just like the question asks, how do I remove the title from the action sheet below?就像问题问的那样,如何从下面的操作表中删除标题? I'm using iOS 14, don't want to upgrade to SwiftUI 3. There's no initializer for the actionSheet with a titleVisibility parameter or anything like that.我正在使用 iOS 14,不想升级到SwiftUI 3. 没有带有 titleVisibility 参数或类似参数的 actionSheet 的初始化程序。 I also tried 'nil' as you can see below, but it's not optional.正如您在下面看到的,我也尝试了“nil”,但它不是可选的。 Not sure how to make the title disappear.不确定如何使标题消失。

@State var showOptions: Bool = false
Button(action: {
    showOptions = true
}, label: {

}).actionSheet(isPresented: $showOptions) {
ActionSheet(
    title: nil,
    buttons: [
        .cancel(),
        .default(Text("Red")) {
            print("x")
        },

        .default(Text("Green")) {
            print("y")
        },

        .default(Text("Blue")) {
            print("z")
        },
        ]
    )
}

ConfirmationDialog can be used to show Action Sheet behaviour without title. ConfirmationDialog可用于显示没有标题的操作表行为。

struct ContentView: View {
    @State private var showingOptions = false
    @State private var selection = "None"

    var body: some View {
        VStack {
            Text(selection)
            Button("Confirm paint color") {
                showingOptions = true
            }
            .confirmationDialog("", isPresented: $showingOptions, titleVisibility: .automatic) {
                ForEach(["Red", "Green", "Blue"], id: \.self) { color in
                    Button(color) {
                        selection = color
                    }
                }
            }
        }.frame(width:300, height: 600)
    }
}

Result of above code上述代码的结果

For iOS 14对于 iOS 14

You can pass empty ActionSheet title like title: Text("")您可以传递空的 ActionSheet标题,例如title: Text("")

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM