GeometryReader
SwiftUI maket: GeometryReader
GeometryReader yordamida ota element o‘lchami va joylashuvini o‘qib, moslashuvchan (responsive) maketlar yarating.
GeometryReader
Moslashuvchan maketlar yaratish uchun ota element o‘lchami va joylashuvini o‘qishda GeometryReader dan foydalaning.
Misol
import SwiftUI
struct GeometryDemo: View {
var body: some View {
GeometryReader { geo in
VStack(spacing: 12) {
Text("Width: \(Int(geo.size.width))")
Text("Height: \(Int(geo.size.height))")
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
.background(.orange.opacity(0.1))
}
}
import SwiftUI
struct ContentView: View {
var body: some View { GeometryDemo() }
}
import SwiftUI
@main
struct MyApp: App {
var body: some Scene { WindowGroup { ContentView() } }
}
Moslashuvchan joylashtirish
Elementlarni konteyner o‘lchamiga qarab GeometryReader, alignment va offset yordamida joylashtiring.
Sintaksis:
GeometryReader { geo in ... }.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottomTrailing).offset(x: 0, y: -12)
Misol
import SwiftUI
struct GeometryPositionDemo: View {
var body: some View {
GeometryReader { geo in
ZStack {
Color.orange.opacity(0.1)
Text("Bottom Right")
.padding(8)
.background(.thinMaterial, in: Capsule())
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottomTrailing)
.offset(x: 0, y: -12)
}
}
}
}
import SwiftUI
struct ContentView: View {
var body: some View { GeometryPositionDemo() }
}
import SwiftUI
@main
struct MyApp: App {
var body: some Scene { WindowGroup { ContentView() } }
}
W3Schools Pathfinder
Yutuqlaringizni kuzating – bu bepul!
