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

效果图:

相关推荐
szarron15 分钟前
HTOOL‑SA12 + HT06 近场探头组合实操|手持设备工位 EMI 预兼容排查完整流程
运维·服务器·开发语言·网络·射频工程·频谱仪
杨云龙UP15 分钟前
DB2 HADR 主备架构活动日志参数优化操作手册
linux·运维·服务器·数据库·db2·db2 hadr·日志参数调整
我是大猴子20 分钟前
MyBatis‑Plus & MyBatis‑Flex 区别
java·服务器·数据库
csdn_aspnet26 分钟前
如何从电脑主机拷东西到VWmare虚拟机
linux·运维·服务器·windows·vmware·虚拟机
码农幻想梦34 分钟前
“找不到 www.bilibili.com 的服务器 IP 地址”解决办法
运维·服务器·tcp/ip
gf13211111 小时前
python_调用远程服务器上的openclaw
服务器·python·php
Huangjin007_1 小时前
【Linux 系统篇(二十)】进程(八):进程创建、进程退出
linux·运维·服务器
starzy19902 小时前
Flink TimeWindow 详解及代码实现:从三种时间语义到滚动与滑动窗口
java·服务器·flink
Shadow(⊙o⊙)2 小时前
epoll三大接口到内核+正确认识应用层与内核的联系(6000字)
linux·服务器·网络
captain3762 小时前
网络原理(4)-TCP
java·服务器·网络·网络协议·tcp/ip·java-ee