alignment in GeometryReader
Last updated
Last updated
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)
}
}
}