Learn Courses My Dashboard

Module 4, Lesson 4 Challenge

Here is the solution of the code:

//
//  ContentView.swift
//  Practice-9-Geometory
//
//  Created by Sam Grover on 08/06/22.
//

import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack (spacing:0){
            ZStack {
                GeometryReader{
                    geo in
                    Rectangle().foregroundColor(.green).frame(height: geo.size.height)
                }.ignoresSafeArea()
                
                GeometryReader{
                    geo in
                    Rectangle().foregroundColor(.red).frame(width: geo.size.width/3*2, height: geo.size.height/4, alignment: .center).position(x: geo.size.width/2, y: geo.size.height/2)
                }.ignoresSafeArea()
            }
            
            HStack (spacing: 0){
                GeometryReader{
                    geo in
                    Rectangle().foregroundColor(.purple)
                }.ignoresSafeArea()
                GeometryReader{
                    geo in
                    Rectangle().foregroundColor(.orange)
                }.ignoresSafeArea()
            }
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}