// // ContentView.swift // Memorize // // Created by ching on 2023/2/12. // import SwiftUI struct ContentView: View { var emojis = ["🚌", "🚙", "🚗", "🚕", "🏎", "🚎", "🚓"] @State var emojiCount = 2 var body: some View { VStack { ScrollView { LazyVGrid(columns: [GridItem(.adaptive(minimum: 65))]) { ForEach(emojis[0 ..< emojiCount], id: \.self) { emoji in CardView(content: emoji).aspectRatio(2 / 3, contentMode: .fit) } } } .foregroundColor(/*@START_MENU_TOKEN@*/ .red/*@END_MENU_TOKEN@*/) .padding(.horizontal) .font(.largeTitle) } .padding(.horizontal) } } struct CardView: View { @State var isFaceUp: Bool = true var content: String var body: some View { ZStack { let shape = RoundedRectangle(cornerRadius: 20.0) if isFaceUp { shape .fill() .foregroundColor(.white) shape .strokeBorder(lineWidth: 3) Text(content) .font(.largeTitle) } else { shape .fill() } } .onTapGesture { isFaceUp = !isFaceUp } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() .preferredColorScheme(.dark) ContentView() .preferredColorScheme(.light) } }