SwiftUI - ActionSheet Example.
This tutorial is to display ActionSheet in SwiftUI. As you know in Swift we are using UIAlertController to display actionsheet popup over the screen. Now here in SwiftUI we have a class name ActionSheet to do some thing. Here we are study how to play with ActionSheet via SwiftUI and How handle the action. first you create SwiftUI Project.
Full Code of ActionSheet SwiftUI:
Output:
You are study to "UIAlertController in swift", Now this tutorial for Alert in SwiftUI.
Before the tutorial you will check "SwiftUI Text" and "SwiftUI Button", because In this tutorial we are use also "Text and "Button".
Here we define ActionSheet with title and Save, delete and cancel button with it's action.
Here we define ActionSheet with title and Save, delete and cancel button with it's action.
Full Code of ActionSheet SwiftUI:
12345678910111213141516171819202122232425262728293031323334353637// Created by Kirit Modi on 17/09/19.
// Copyright © 2019 iOSDevCenters. All rights reserved.
//
import SwiftUI
struct ContentView: View {
@State private var isActionSheet = false
var body: some View {
Button(action: {
self.isActionSheet = true
}) {
Text("ActionSheet")
.foregroundColor(Color.white)
}
.padding()
.background(Color.blue)
.actionSheet(isPresented: $isActionSheet, content: {
ActionSheet(title: Text("iOSDevCenters"), message: Text("SubTitle"), buttons: [
.default(Text("Save"), action: {
print("Save")
}),
.default(Text("Delete"), action: {
print("Delete")
}),
.destructive(Text("Cancel"))
])
})
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Output:
SwiftUI - ActionSheet Example.
Reviewed by KIRIT MODI
on
00:30:00
Rating:
