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

效果图:

相关推荐
CHHH_HHH29 分钟前
【Linux系统篇】深入解析Linux文件系统:从磁盘寻址到软硬链接
linux·服务器·开发语言·后端·ubuntu
剑锋所指,所向披靡!29 分钟前
TCP并发服务器
服务器·网络·tcp/ip
刚入门的大一新生1 小时前
Linux-Linux的进程状态
linux·运维·服务器
AI备忘录1 小时前
(十一)DHCP 配置命令五厂商对照:华为 华三 锐捷 迈普 思科
服务器·网络·网络协议·网络安全·华为
随便做点啥2 小时前
32卡×4090 24GB,Qwen3.8-27B-FP8 集群部署报告
服务器·经验分享·docker·vllm
Brilliantwxx2 小时前
313131
服务器
00后程序员张2 小时前
iOS 开发全流程需要哪些工具?编码、调试、构建、发布阶段选择
ide·vscode·ios·objective-c·个人开发·swift·敏捷流程
暴力求解11 小时前
Linux网络---传输层协议TCP(二)
linux·服务器·开发语言·网络·tcp/ip
游戏开发爱好者813 小时前
WebSocket 抓包怎么查看内容?从握手到消息帧完整解读
网络协议·计算机网络·网络安全·ios·adb·https·udp