Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaisukeNagata/d010ece5bacd8416119f48d65308a6c4 to your computer and use it in GitHub Desktop.
Save DaisukeNagata/d010ece5bacd8416119f48d65308a6c4 to your computer and use it in GitHub Desktop.
SwiftUI_NavigationView
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
VStack {
Text("Hello, World!")
CommonButton(0)
}
.background(Color.blue)
}
}
}
struct ContentView2: View {
var body: some View {
VStack {
Text("Hello, World!2")
.background(Color.red)
.foregroundColor(Color.white)
CommonButton(1)
.padding(.bottom)
.padding(.bottom)
}
.background(Color.purple)
.edgesIgnoringSafeArea(.bottom)
}
}
struct ContentView3: View {
var body: some View {
VStack {
Group {
Spacer()
Spacer()
Spacer()
Spacer()
Spacer()
Spacer()
}
Group {
Spacer()
Spacer()
Spacer()
Spacer()
Spacer()
Spacer()
}
Group {
Spacer()
Spacer()
Spacer()
Spacer()
Spacer()
Spacer()
}
Text("Hello, World!3")
CommonButton(2)
.padding(.bottom)
.padding(.bottom)
}
.edgesIgnoringSafeArea(.all)
}
}
struct ContentView4: View {
var body: some View {
VStack {
ContentSpace()
Text("Hello, World!4")
ContentSpace()
}
.edgesIgnoringSafeArea(.all)
}
}
struct ContentSpace: View {
var body: some View {
VStack {
Group {
Spacer()
Spacer()
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct CommonButton: View {
var id: Int?
@State var tag: Int?
@State var destination: AnyView?
init(_ id: Int) {
self.id = id
}
var body: some View {
VStack {
Spacer()
Button(action: {
if self.id == 0 {
self.tag = 0
self.destination = AnyView(ContentView2())
} else if self.id == 1 {
self.tag = 1
self.destination = AnyView(ContentView3())
} else if self.id == 2 {
self.tag = 2
self.destination = AnyView(ContentView4())
}
}) {
Text("次へ")
.frame(minWidth: 0, maxWidth: .infinity)
.foregroundColor(Color.red)
}
.background(Color.gray)
.padding(.horizontal)
NavigationLink(destination: self.destination, tag: self.tag ?? 0, selection: $tag) {
EmptyView()
}
}
}
}
@DaisukeNagata
Copy link
Author

Movie

@DaisukeNagata
Copy link
Author

DaisukeNagata commented Mar 7, 2020

X系以外は
https://gist.github.com/daisukenagata/3897782246db07fb7b64b8e791ddb842
safeareaをヒントにしてください。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment