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

效果图:

相关推荐
初级代码游戏2 小时前
iOS只剩美工了吗?时间都被遮盖看不清了
ios·界面设计·美工
TG:@yunlaoda360 云老大3 小时前
华为云国际站代理商备份策略设置过程中遇到问题如何解决?
服务器·数据库·华为云
手揽回忆怎么睡4 小时前
Alibaba Linux 8安装jdk25
linux·运维·服务器
萌萌哒草头将军5 小时前
AudioDock:服务器和 NAS 音频播放最棒的软件!🚀🚀🚀
服务器·docker·node.js
lifewange5 小时前
测试场景 Linux 命令速查表
linux·运维·服务器
就叫飞六吧6 小时前
JSONPath“隔空取物”思想,直击JSON深处的目标字段
服务器·windows·json
姚青&6 小时前
Linux 命令介绍以及帮助命令介绍
linux·运维·服务器
遇见火星6 小时前
详解 Linux 中的 /etc/fstab 文件
linux·运维·服务器
2301_773730316 小时前
网络编程—TCP传输控制协议
服务器·网络·tcp/ip
TG:@yunlaoda360 云老大6 小时前
华为云国际站代理商HiLens的技术优势对跨境客户有哪些具体帮助?
服务器·数据库·华为云