Reputation: 9830
I am using SwiftUI
and want to position a Text
element at the top of the screen.
My code looks like as follows and the output is below. As you can see it is in the middle of the screen. Can anyone advise how to update the position? I have tried to add alignment
properties with little or no success.
import SwiftUI
struct ContentView: View {
var body: some View {
Text("Hello World!")
}
}
Upvotes: 1
Views: 1124
Reputation: 54641
I have tried to add alignment properties with little or no success.
Alternatively, you can use frame
with the .top
alignment:
struct ContentView: View {
var body: some View {
Text("Hello World!")
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
}
}
Upvotes: 2
Reputation: 96
You can use a Spacer()
after the Text View to push it upwards.
struct ContentView: View {
var body: some View {
VStack {
Text("Hello World!")
Spacer()
}
}
}
Upvotes: 4