I'm trying to display the contents of a text file in a ScrollView that has both vertical and horizontal scrolling.
All is well when then contents of the file are large enough to fill the screen. However, for smaller files e.g. only 3 lines, the text is displayed, but in the middle of the screen. I've tried adding a Spacer() in various places but this does not help. Also, removing the horizontal scrolling pushes the contents to the top, but I need both vertical and horizontal scrolling.
Here's some example code showing the problem:
struct ContentView: View {
var string = """
Line 1 - Lorem ipsum dolor sit amet, consectetur adipiscing elit
Line 2 - Lorem ipsum dolor sit amet, consectetur adipiscing elit
Line 3 - Lorem ipsum dolor sit amet, consectetur adipiscing elit
"""
var body: some View {
NavigationView {
ScrollView([.horizontal, .vertical]) {
Text(string)
Spacer()
}
.padding()
.navigationTitle("Scrolling")
}
}
}
Here's a link to a screenshot of the problem - 
Does anyone know how to push the contents of the ScrollView to the top of the screen?
Thanks.
Gavin