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

效果图:

相关推荐
阿巴~阿巴~几秒前
Redis重大版本演进全解析:从2.6到7.0
服务器·数据库·redis·ubuntu·缓存·centos
00后程序员张17 分钟前
Swoole HTTPS 实战,在生产环境部署、性能权衡与排查流程
后端·ios·小程序·https·uni-app·iphone·swoole
liulilittle22 分钟前
HI3798MV100 运营商机顶盒NAS LINUX OS - IP地址静态绑定指南
linux·运维·服务器·网络·tcp/ip·nas·机顶盒
我命由我1234526 分钟前
PDFBox - PDDocument 与 byte 数组、PDF 加密
java·服务器·前端·后端·学习·java-ee·pdf
算力魔方AIPC3 小时前
PP-OCRv5 MCP服务器在海光主板的部署与实战
运维·服务器
dyxal3 小时前
内网windows系统机器通过vscode ssh连接内网服务器,无网络导致的一系列无法正常连接问题
服务器·vscode·ssh
云动雨颤3 小时前
WordPress提速指南:Memcached+Super Static Cache+CDN缓存网站内容
服务器·memcached·cdn
blackorbird3 小时前
使用 Overpass Turbo 查找监控摄像头
运维·服务器·数据库·windows
2501_915909064 小时前
iOS App 上架全流程详解:证书配置、打包上传、审核技巧与跨平台上架工具 开心上架 实践
android·ios·小程序·https·uni-app·iphone·webview
2501_915106324 小时前
iOS 26 系统流畅度测试实战分享,多工具组合辅助策略
android·macos·ios·小程序·uni-app·cocoa·iphone