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

效果图:

相关推荐
风落无尘8 小时前
《智能重生:从垃圾堆到AI工程师》——第五章 代码与灵魂
服务器·网络·人工智能
南境十里·墨染春水12 小时前
linux学习笔记 网络编程——Socket入门与TCP客户端/服务器实现
linux·服务器·网络
Sirens.13 小时前
twikoo:从MongoDB Atlas到本地部署
运维·服务器
DFT计算杂谈13 小时前
自动化脚本一键绘制三元化合物相图
java·运维·服务器·开发语言·前端·python·自动化
Yupureki14 小时前
《Linux网络编程》6.UDP原理
linux·运维·服务器·网络·udp
楼田莉子14 小时前
Linux网络:NAT_代理
linux·运维·服务器·开发语言·c++·后端
fish_xk16 小时前
Linux的权限
linux·运维·服务器
Sirens.18 小时前
Umami:从Cloud迁移到服务器
运维·服务器
练习时长一年18 小时前
分页插件冲突问题
服务器·前端·windows
春蕾夏荷_72829772519 小时前
2、c++ acl tcp服务器客户端简单实例-服务器端(1)
服务器·c++·tcp/ip