SwiftUI中的ActionSheet
记录一下SwiftUI中的ActionSheet的用法
swift
import SwiftUI
struct ActionSheetBootCamp: View {
@State var showActionSheetBool = false
var body: some View {
ZStack {
Color.purple.ignoresSafeArea()
Button {
showActionSheetBool.toggle()
} label: {
Text("showActionSheet")
.foregroundColor(.white)
.padding()
}
}
.actionSheet(isPresented: $showActionSheetBool, content: {
showActionSheet()
})
}
func showActionSheet() -> ActionSheet {
let button1: ActionSheet.Button = .default(Text("default"))
let button2: ActionSheet.Button = .destructive(Text("destructive"))
let cancel: ActionSheet.Button = .cancel()
return ActionSheet(title: Text("this is title"), message: Text("this is message"), buttons: [button1, button2, cancel])
}
}
#Preview {
ActionSheetBootCamp()
}
效果图: