How can I justify a Text in SwiftUI?

Viewed 115

here is my code for what I want get Justified, how could I do that?

my goal:

enter image description here

curent issue:

enter image description here

the code:

    struct ContentView: View {
    
    @State var stringOfText: String = String()
    
    var body: some View {

        Text(stringOfText).font(Font.body.bold()).padding()
 
        Button("Justiy it!") {

            stringOfText = Array(2...100).reduce("1", ({$0 + " " + String($1)}))
            
        }
   
    }
}
2 Answers

You can use a monospaced font for this, here is a example with Courier.

Text(
  (1...100).map { $0.description }.joined(separator: " ")
).font(Font.custom("Courier", size: 17))

enter image description here

Related