Skip to content

Instantly share code, notes, and snippets.

@takoikatakotako
Created October 23, 2024 16:31
Show Gist options
  • Select an option

  • Save takoikatakotako/b4b058b9953ba6aa17f3a9f2f2e5a9fd to your computer and use it in GitHub Desktop.

Select an option

Save takoikatakotako/b4b058b9953ba6aa17f3a9f2f2e5a9fd to your computer and use it in GitHub Desktop.
SwiftUIでボタンを押すとポップアップを表示する
import SwiftUI
struct ContentView: View {
@State var showingPopUp = false
var body: some View {
ZStack {
Button(action: {
withAnimation {
showingPopUp = true
}
}, label: {
Text("Tap Me!!")
.padding()
.background(Color.white)
.cornerRadius(12)
})
if showingPopUp {
PopupView(isPresent: $showingPopUp)
}
}
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
.background(Color.gray)
.ignoresSafeArea()
}
}
#Preview {
ContentView()
}
import SwiftUI
struct PopupView: View {
@Binding var isPresent: Bool
var body: some View {
VStack(spacing: 12) {
Text("Snorlax")
.font(Font.system(size: 18).bold())
Image("icon")
.resizable()
.frame(width: 80, height: 80)
Text("Snorlax (Japanese: カビゴン Kabigon) is a Normal-type Pokemon. Snorlax is most popular Pokemon.")
.font(Font.system(size: 18))
Button(action: {
withAnimation {
isPresent = false
}
}, label: {
Text("Close")
})
}
.frame(width: 280, alignment: .center)
.padding()
.background(Color.white)
.cornerRadius(12)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment