How to make VStack take full screen width in SwiftUI
Hello, colleagues! I'm new to SwiftUI and have been struggling for days with what seems like a simple task. I need VStack to stretch across the full screen width, but by default it adjusts to the size of its content.
Here's my code:
```swift
struct ContentView: View {
var body: some View {
VStack {
Text("Hello, world!")
.font(.largeTitle)
Text("This is text inside VStack")
.font(.body)
}
.background(Color.blue)
}
}
```
I expected the blue background to fill the entire screen width, but instead the VStack only wraps around the text. I tried adding `.frame(maxWidth: .infinity)`, but it didn't work — the background remained narrow.
I also tried wrapping the VStack in a ZStack or HStack, but
No answers yet.
Log in to leave an answer
Blogs
Functional Programming in C#: From A to Z — A Complete Guide
Implicitly Unwrapped Optionals: Why Are They Needed If We Know the Value?
Containerization of C# Applications in Docker: Advanced Level
Generics in Rust: Don't Fear Abstractions, Write Code Like a Pro