Skip to content

Instantly share code, notes, and snippets.

@ole
Created March 28, 2021 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ole/919a485586d1313259f9631f753e2c0f to your computer and use it in GitHub Desktop.
Save ole/919a485586d1313259f9631f753e2c0f to your computer and use it in GitHub Desktop.
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
Copy link
Author

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