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

效果图:

相关推荐
网易易盾1 小时前
iOS 设备环境核验接入实践:从特征扫描到运行时完整性识别
ios
Kainy1 小时前
生产服务器从机械盘迁移NVMe固态:旧盘不动、退路先行的六步实操全记录
运维·服务器
无足鸟ICT5 小时前
【RHCA+】_proc_pid_attr_exec
linux·运维·服务器
FlightYe19 小时前
linux系统编程(二十一):C 语言常见坑
android·linux·运维·服务器·c语言·音视频
by2099920 小时前
Linux 文件描述符与重定向
linux·服务器
橙橙笔记20 小时前
Linux基础与命令的学习
linux·运维·服务器·shell
无奈笑天下20 小时前
银河麒麟桌面操作系统【命令行配置文件与图片搜索功能】操作方法
linux·运维·服务器
布莱克60521 小时前
Swift 自动引用计数(ARC)详解:原理、循环引用与最佳实践
开发语言·ios·swift·arc·自动引用计数
.道阻且长.1 天前
Linux基础IO:理解文件以及回顾C文件接口
linux·运维·服务器·c语言·开发语言·职场和发展
丘山录1 天前
本地部署 DGX Spark,200G 网卡挂在 4 条通道上
服务器·人工智能·spark·持续部署