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

效果图:

相关推荐
普罗米拉稀43 分钟前
Flutter 复用艺术:Mixin 与 Abstract 的架构哲学与线性化解密
flutter·ios·面试
phoenix09814 小时前
Linux入门DAY27
linux·运维·服务器
xw55 小时前
免费的个人网站托管-PinMe篇
服务器·前端
egoist20236 小时前
【Linux仓库】进程创建与进程终止【进程·柒】
linux·运维·服务器·进程创建·写时拷贝·进程终止
大锦终6 小时前
【Linux】文件系统
linux·服务器·c++
Kyln.Wu7 小时前
【python实用小脚本-190】Python一键删除PDF任意页:输入页码秒出干净文件——再也不用在线裁剪排队
服务器·python·pdf
枫叶丹48 小时前
【Qt开发】常用控件(五)
服务器·前端·qt
kymjs张涛8 小时前
零一开源|前沿技术周刊 #12
ios·google·github
励志五个月成为嵌入式糕手9 小时前
0819 使用IP多路复用实现TCP并发服务器
java·服务器·tcp/ip
华纳云IDC服务商9 小时前
服务器Linux防火墙怎样实现访问控制
linux·运维·服务器