作者:永和邮政 | 来源:互联网 | 2023-10-15 21:13
源码地址:https:github.comfzhleeSwiftUI-Guide当点击按钮时,弹出Modl模态窗口。示例代码:structContentView:View{@S
源码地址:https://github.com/fzhlee/SwiftUI-Guide
当点击按钮时,弹出Modl模态窗口。
示例代码:
struct ContentView : View {
@State var isPresented = false
var body: some View {
VStack{
Button("Show modal") {
self.isPresented = true
}.sheet(isPresented: $isPresented, content: {
MyDetailView(message: "Modal window")
})
}
}
}
struct MyDetailView: View {
let message: String
var body: some View {
VStack {
Text(message)
.font(.largeTitle)
}
}
}
查看点击按钮之后的运行结果: