23:SwiftUI-Alert

 

 

正文

//
//  AlertPage.swift
//  SwiftUIDeom
//
//  Created by zhoukang03 on 2023/3/28.
//

import SwiftUI

struct AlertPage : View {
    
    @State var showAlert = false
    
    var body: some View {
        Button(action: {
            self.showAlert = true
            print("Tap")
        }) {
            Text("Click")
                .font(.system(size: 40,
                              design: .rounded))
        }
        .alert(isPresented: $showAlert, content: {
            Alert(title: Text("温馨提示"),
                  message: Text("确定删除吗?"),
                  primaryButton: .destructive(Text("确认")) { print("确定") },
                  secondaryButton: .cancel())
        }).navigationBarTitle(Text("Alert"))
        
    }
}

#if DEBUG
struct AlertPage_Previews : PreviewProvider {
    static var previews: some View {
        AlertPage()
    }
}
#endif

 

 

示例图

 

posted on 2023-03-28 16:30  风zk  阅读(68)  评论(0编辑  收藏  举报

导航