I'm building the step-by-step view (Paged Scrolling View with PageTabViewStyle
)
I tried to put the images and the text in a ZStack but that did not solve the problem.
I added a Spacer()
with padding, also failed.
What confuses me, is that whenever I comment out the PageTabViewStyle, the positioning is correct but the TabView breaks ALTHOUGH it wrapped at the right bracket.
Watch here https://i.stack.imgur.com/WVG3V.jpg
Ideally, the image should be top trailing, ignoring the safe area and the NavigationBar. With the text sitting just underneath. How do I achieve this?
struct ContentView: View {
var recipe: Recipe
var body: some View {
TabView {
ForEach(0..<recipe.directions.count) { x in
ScrollView(.vertical, showsIndicators: false) {
VStack {
Image(recipe.images[x])
.resizable()
.aspectRatio(contentMode: .fit)
Spacer()
Text(recipe.directions[x])
.font(.system(size: 29, weight: .medium))
.foregroundColor(.primary)
.padding()
}.navigationTitle("")
}.edgesIgnoringSafeArea(.top)
}
}
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
NavigationView {
ContentView(recipe: recipesData[0])
}
}
}
Data File
struct Recipe: Identifiable {
var id = UUID()
var directions: [String]
var images: [String]
}
let recipesData: [Recipe] = [
Recipe(
directions: [
"Gather all ingredients on your countertop.",
"Make the pesto by washing the parsley and mint. Slice tomatoes",
"Cut the cucumber and measure 1 cup walnuts, 1/2 cup walnut oil and 2 tbsp of lemon juice.",
],
images: [
"step1",
"step2",
"step3"
]
)
]