Created
March 28, 2021 07:39
-
-
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?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result: