swiftUI系统默认弹窗内容,弹出系统自带的弹窗内容,左右两个按钮取消,确定,点击过后消失弹窗。
struct defaultAlert: View {
@State private var showingAlert = false
var body: some View {
VStack{
Text("2qwsd")
Button("Show Alert") {
self.showingAlert = true
}//button
.alert(isPresented: $showingAlert)//一种双向数据绑定,这是因为SwiftUI会在警报解除后自动将showingAlert设置为false
{
Alert(title:Text("停车时间:51分!\n停车费用5元"),
message: Text("收费标准:5元/1小时,15分钟内免费,不足1小时按1小时计费,每24小时封顶80元,总封顶299元。"),
primaryButton: .default(
Text("取消"),
action: {
print("取消")
}),
secondaryButton: .destructive(
Text("支付"),
action: {
print("支付")
}
)
)//Alert
}//alert
}//VStack
}}