Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SwiftUI alignment guide layout. Why is the rectangle drawn out of bounds of the stack view?
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
// Why is the rectangle drawn out of bounds of the stack view?
Rectangle().fill(Color.green)
.frame(width: 100, height: 40)
.alignmentGuide(HorizontalAlignment.center) { _ in 0 }
}
.border(Color.red)
.padding()
// To prevent clipping
.frame(width: 300, height: 200)
.border(Color.blue)
}
}
import PlaygroundSupport
let view = ContentView()
PlaygroundPage.current.setLiveView(view)
@ole

This comment has been minimized.

Copy link
Owner Author

@ole ole commented Mar 28, 2021

Result:

rendering-1

rendering-2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment