Applying .position() will change view's frame and become a "push-out" view. 👉 Paul
absolute position in its parent’s coordinate space.
will change frame and become a "push-out" view.
relative to its original position.
won't change frame.
import SwiftUI struct PositionView: View { let text = Text("Hello SwiftUI") var body: some View { HStack { Group { // 1. original text text // ⭐️ 2. offset: frame unchanged // (⭐️ so is background) text.offset(x: 0, y: 50) // ⭐️ 3. if you want to move background too, // have to apply .background() first. text .background(.indigo) .offset(x: 0, y: 50) // ⭐️ 4. position: frame changed❗️ text.position(x: 0, y: 50) } .padding(.horizontal, 6) .background(.pink) .frame(width: 150, height: 150) .border(.white(0.4)) } } }
SwiftOnTap ⟩ View ⟩ .position(_:)
SwiftUI ⟩ View Layout and Presentation
Making Fine Adjustments to a View's Position
offset(x:y:)
position(x:y:)
Paul ⟩ Absolute positioning for SwiftUI views ⭐️ differences between .position & .offset
Point
Last updated 3 years ago
Was this helpful?