I have been trying to create an app based on Module 1 using a Toggle Switch to use two different assets like flashcards for numbers and alphabets. I am getting tied up in knots. I am attaching a copy of the program to get some advice from you.
import SwiftUI
struct ContentView: View {
@State var playerCard = “card1”
@State var toggleIsOn: Bool = false
@State var alphabet = “acard1”
var body: some View {
ZStack {
Image("background-plain")
.resizable()
.aspectRatio(contentMode: .fill)
.ignoresSafeArea()
VStack(spacing: 12.0) {
HStack {
Spacer()
Image("KidsPicture")
.renderingMode(.original)
.resizable(capInsets: EdgeInsets(top: 0.0, leading: 0.0, bottom: 0.0, trailing: 0.0), resizingMode: .stretch)
.aspectRatio(contentMode: .fit)
Spacer()
.frame(width: 15)
Text(toggleIsOn ? "NUMBERS" : "ALPHABET")
.font(.title2)
.fontWeight(.bold)
.foregroundColor(Color.white)
Toggle(isOn: $toggleIsOn, label: {
})
}
if (toggleIsOn) {
Image(playerCard)
.frame(width: 430.0)
.cornerRadius(50)
}
Spacer()
Button("PRESS") {
press()
}
.padding()
.foregroundColor(.white)
.fontWeight(/*@START_MENU_TOKEN@*/.heavy/*@END_MENU_TOKEN@*/)
.background(/*@START_MENU_TOKEN@*//*@PLACEHOLDER=View@*/Color.orange/*@END_MENU_TOKEN@*/)
.border(/*@START_MENU_TOKEN@*/Color.black/*@END_MENU_TOKEN@*/, width: /*@START_MENU_TOKEN@*/3/*@END_MENU_TOKEN@*/)
.cornerRadius(/*@START_MENU_TOKEN@*/6.0/*@END_MENU_TOKEN@*/)
.buttonBorderShape(/*@START_MENU_TOKEN@*//*@PLACEHOLDER=shape: ButtonBorderShape@*/.automatic/*@END_MENU_TOKEN@*/)
.accessibilityLabel(/*@START_MENU_TOKEN@*/"Label"/*@END_MENU_TOKEN@*/)
.font(/*@START_MENU_TOKEN@*/.headline/*@END_MENU_TOKEN@*/)
Spacer()
}
Spacer()
Spacer()
Spacer()
Spacer()
}
}
func press() {
//randomize the card
let playerCardValue = Int.random(in: 1...5)
playerCard = "card1" + String(playerCardValue)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}