IOS/SwiftUI
(SwiftUI)14.토스트,팝업
프린이0218
2021. 4. 28. 17:21
//
// ContentView.swift
// Toast_popup_tutorial
//
// Created by devdepot on 2021/04/28.
//
import SwiftUI
import ExytePopupView
struct ContentView: View {
@State var shouldShowToast: Bool = false;
func creatTopeSolidMessage() -> some View{
Text("토스트 메세지입니다.")
.padding()
.foregroundColor(Color.white)
.background(Color.blue)
.cornerRadius(10)
}
var body: some View {
ZStack{
VStack{
Button(action: {
self.shouldShowToast = true
}, label: {
Text("토스트 띄우기")
.font(.system(size: 25))
.foregroundColor(Color.white)
.padding()
.background(Color.blue)
.cornerRadius(10)
})
}
}
.popup(isPresented: $shouldShowToast
, type: .toast
, position: .bottom
, animation: .default
, autohideIn: 2 //2초가 지난 후 자동으로 사라짐
, closeOnTap: true
, closeOnTapOutside: true
, view: {
creatTopeSolidMessage()
})
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}