Reputation: 159
import SwiftUI
struct Test: View {
var body: some View {
VStack{
Text("dklf")
}
.frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
}
}
Why is the VStack not aligned in the middle of the Screen vertically?
Upvotes: 1
Views: 374
Reputation: 258471
UIScreen.main.bounds
does not account for the Safe Area, so this is what you probably wanted:
var body: some View {
VStack{
Text("dklf")
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
Upvotes: 1
Reputation: 159
Ok thanks. I don't understand, why this blue border isn't at the top. If I add .statusBar(hidden: true) after the VStack, the blue border stays also there.
struct Test: View {
var body: some View {
VStack{
Color.yellow
}
.ignoresSafeArea()
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
Upvotes: 0