SwiftUI中的ActionSheet

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()
}

效果图:

相关推荐
开心就好202516 分钟前
移动应用上架到应用商店的完整指南:原理与详细步骤
后端·ios
成都极云科技1 小时前
「算力服务器托管企业」——IDC行业的新方向
运维·服务器
on_pluto_1 小时前
论文GAN(GRAPH ATTENTION NETWORKS)阅读笔记
服务器·人工智能·pytorch·conda
生活很暖很治愈1 小时前
Linux——HTTP协议
linux·服务器·c++·网络协议·ubuntu·http
vortex51 小时前
文件上传漏洞绕过技术总结(含实操指南与防御方案)
linux·服务器·网络安全·渗透测试
江畔何人初2 小时前
HPA是如何在k8s集群实现自动扩缩容机制的
linux·运维·服务器·云原生·kubernetes
杨云龙UP2 小时前
Oracle 19c RAC多节点运行状态最简排查指南_20260316
linux·运维·服务器·数据库·sql·oracle
逆境不可逃2 小时前
【从零入门23种设计模式18】行为型之备忘录模式
服务器·数据库·设计模式·oracle·职场和发展·迭代器模式·备忘录模式
暴力求解2 小时前
Linux---ELF与库加载
linux·运维·服务器
wx_xsooop_wx2 小时前
iOS 被拒 4.3a Cocos【全面解读】
ios