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:
// 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:
Water Hack Burns 2lb of Fat OVERNIGHT
ReplyDeleteAt least 160 000 women and men are utilizing a easy and SECRET "liquid hack" to lose 1-2 lbs each night while they sleep.
It's very simple and it works all the time.
This is how you can do it yourself:
1) Go get a drinking glass and fill it up half the way
2) Proceed to learn this awesome HACK
and be 1-2 lbs thinner as soon as tomorrow!