[SwiftUI]ActionSheetのタイトルを非表示にするには?

SwiftUI

どうも、ちょげ(@chogetarou)です。

ActionSheetのタイトルを非表示にする方法を紹介します。

この記事では、iOS15からActionSheetとして扱われているconfirmationDialogを使っています。

スポンサーリンク

方法

インターフェース, インターネット, プログラム, ブラウザ, Www

ActionSheetのタイトルを非表示にするには、confirmationDialogの引数「titleVisibility」を使います。

具体的には、confirmationDialogの引数「titleVisibility」に「.hidden」を指定します。

SamView()
    .confirmationDialog("Title", isPresented: $isShow, titleVisibility: .hidden) {
    //Actions
}

confirmationDialogの引数「titleVisibility」に「.hidden」を指定することで、ActionSheetのタイトルを非表示するにことが出来ます。

使用例

struct ContentView: View {
    @State var isShow = false
    @State var selectedColor = ""
    var body: some View {
        VStack {
            Text(selectedColor)
                .padding()
            Button("Show") {
                self.isShow = true
            }
            .confirmationDialog("Select Color", isPresented: $isShow, titleVisibility: .hidden) {
                Button("Green") {
                    selectedColor = "Green"
                }
                Button("Yellow") {
                    selectedColor = "Blue"
                }
                Button("Red") {
                    selectedColor = "Red"
                }
            }
        }
    }
}

コメント

タイトルとURLをコピーしました