I have 2 simple views:
import SwiftUI
struct ContentView: View {
@State private var showingModalView = false
var body: some View {
Button(action: {
self.showingModalView.toggle()
}) {
Text("Show Modal View")
}.sheet(isPresented: $showingModalView) {
ModalView()
}
}
}
struct ModalView: View {
var body: some View {
Text("Modal View")
}
}
When "Show Modal" button pressed, ModalView
is show.
How to change text "Cancel" when ModalView
is active to something else?
This Cancel is actually a navigation bar item. You can replace it with own button using toolbar, like
struct ContentView: View {
@State private var showingModalView = false
var body: some View {
Button(action: {
self.showingModalView.toggle()
}) {
Text("Show Modal View")
}.sheet(isPresented: $showingModalView) {
ModalView()
.toolbar(content: {
ToolbarItem(placement: .cancellationAction) {
Button("Close") { self.showingModalView = false }
}
})
}
}
}
also you can hide it at all (and make your custom approach to close, eg. with button in sheet view, etc.)
}.sheet(isPresented: $showingModalView) {
ModalView()
.navigationBarHidden(true)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With