24:SwiftUI-ActionSheet
正文
// // ActionSheetPage.swift // SwiftUIDeom // // Created by zhoukang03 on 2023/3/28. // import SwiftUI struct ActionSheetPage : View { @State var showSheet = false var body: some View { VStack { Button(action: { self.showSheet = true }) { Text("ActionSheet") .bold() .font(.system(.largeTitle, design: .rounded)) } .actionSheet(isPresented: $showSheet, content: {sheet}) } } private var sheet: ActionSheet { let action = ActionSheet(title: Text("Title"), message: Text("Message"), buttons: [.default(Text("Default"), action: { print("Default") self.showSheet = false }),.destructive(Text("destructive"), action: { print("destructive") self.showSheet = false }),.cancel({ print("Cancel") self.showSheet = false })]) return action } } #if DEBUG struct ActionSheetPage_Previews : PreviewProvider { static var previews: some View { ActionSheetPage() } } #endif
示例图