alignment in GeometryReader

import SwiftUI
import PlaygroundSupport
PlaygroundPage.current.setLiveView(ContentView())

struct ContentView: View {
    
    // โญ๏ธ current index
    @State private var selected = 0
    
    var body: some View {
        GeometryReader { proxy in 
            // โญ๏ธ subviews ่‡ชๅ‹•ๅฐ้ฝŠใ€ŒๅทฆไธŠ่ง’ใ€
            Group {
                Color.red.opacity(0.9)
                    .frame(width: 100, height: 100)
                Color.orange.opacity(0.9)
                    .frame(width: 80, height: 80)
                Color.yellow.opacity(0.9)
                    .frame(width: 60, height: 60)
                Color.green.opacity(0.9)
                    .frame(width: 40, height: 40)
            }
            .shadow(radius: 6)
            
            // โญ๏ธ subviews with custom position
            Color.blue.opacity(0.5)
                .frame(width: 40, height: 40)
                .position(.zero)
            Color.purple.opacity(0.5)
                .frame(width: 40, height: 40)
                .position(proxy.size.bottomRight)    // ๐ŸŒ€ CGSize + ๐Ÿ…ฟ๏ธ Rectangular
        }
        .frame(width: 300, height: 40)
        .border(.white.opacity(0.6))
        .overlay {
            Text("**`GeometryReader`**")
                .font(.title3)
                .opacity(0.8)
                .shadow(radius: 4)
        }
    }
}

Last updated