.alignmentGuide(.leading) { d in d[.trailing] }
VStack(alignment: .leading) {
ForEach(0..<10) { position in
Text("Number \(position)")
.alignmentGuide(.leading) { _ in Double(position) * -10 }
}
}
.background(.red)
.frame(width: 400, height: 400)
.background(.blue)
struct ContentView: View {
var body: some View {
HStack(alignment: .midAccountAndName) {
VStack {
Text("@twostraws")
.alignmentGuide(.midAccountAndName) { d in d[VerticalAlignment.center]}
Image(.example)
.resizable()
.frame(width: 64, height: 64)
}
VStack {
Text("Full name:")
.alignmentGuide(.midAccountAndName) { d in d[VerticalAlignment.center]}
Text("PAUL HUDSON")
.font(.largeTitle)
}
}
}
}
extension VerticalAlignment {
struct MidAccountAndName: AlignmentID {
static func defaultValue(in context: ViewDimensions) -> CGFloat {
context[.top]
}
}
static let midAccountAndName = VerticalAlignment(MidAccountAndName.self)
}
.scrollTargetBehavior(.viewAligned)
- Presenting Sheets with conditionals
struct User: Identifiable {
var id = "Desmond Sofua"
}
struct ContentView: View {
@State private var selectedUser: User? = nil
@State private var isShowingUser = false
var body: some View {
Button("Tap Me") {
selectedUser = User()
}
.sheet(item: $selectedUser) { user in
Text(user.id)
.presentationDetents([.medium, .large])
}
}
}