'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. I also tried 'nil' as you can see below, but it's not optional. 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")
},
]
)
}
Solution 1:[1]
ConfirmationDialog can be used to show Action Sheet behaviour without title.
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)
}
}
Solution 2:[2]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Toseef Khilji |

