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

效果图:

相关推荐
机器视觉知识推荐、就业指导31 分钟前
Qt 小技巧:如何用 Q_PROPERTY 管理属性
服务器·数据库·qt
星辰&与海41 分钟前
操作系统引导过程
服务器
张心独酌1 小时前
Rust开发案例库-静态服务器
服务器·开发语言·rust
起个名字费劲死了1 小时前
QT + Socket 客户端/服务端 公网通讯
服务器·c++·qt·socket
HarmonLTS2 小时前
Python Socket网络通信详解
服务器·python·网络安全
sun0077002 小时前
androd和qnx判断实网卡还是虚网卡
运维·服务器·网络
郝学胜-神的一滴2 小时前
Python数据封装与私有属性:保护你的数据安全
linux·服务器·开发语言·python·程序人生
Zender Han2 小时前
Flutter Android 启动页 & App 图标替换(不使用任何插件的完整实践)
android·flutter·ios
口嗨农民工2 小时前
live555 sample基本解读
运维·服务器
小宇的天下3 小时前
Synopsys Technology File and Routing Rules Reference Manual (1)
java·服务器·前端