SwiftUI Divider
behaves as if it has frame(maxWidth: .infinity)
. So it widens its parent view.
How can I prevent Divider from widening its parent view in the below code?
HStack {
VStack {
Text("AAA")
Divider()
Text("BBB")
}
.background(Color.orange)
Text("BodyBodyBodyBodyBodyBodyBodyBodyBodyBody")
.frame(maxWidth: .infinity)
.background(Color.blue)
}
2
Answers
You can use
fixedSize
(https://developer.apple.com/documentation/swiftui/view/fixedsize()):Try this:
Output: