'SwiftUI weird multiline text justification
I have a multiline Text that does not correctly fill out the available width. The code is as follows:
struct ContentView: View {
let title = "Standard 1 hour - SYLVAIN MASSON"
var body: some View {
VStack {
Text(self.title)
.multilineTextAlignment(.leading)
.border(Color.yellow, width: 1)
.frame(maxWidth: .infinity, alignment: .leading)
.border(Color.green, width: 2)
Text(self.title)
.lineLimit(0)
}
.padding(60)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
.previewDevice("iPhone 12 mini")
}
}
The result in the preview (running as an iPhone 12 mini) is as follows:
As shown by the second Text
, the available space is such that I would expect the first Text
to display two lines:
Standard 1 hour - SYLVAIN
MASSON
Instead it displays
Standard 1 hour -
SYLVAIN MASSON
Why?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|