Set Line Spacing in SwiftUI TextView

SwiftUI provides lineSpacing() modifier that can set space between the lines of Text view text in the view. In this tutorial, you are going to learn how to set line spacing for the text of a Text view in SwiftUI.

Without wasting any time, let’s see our first example:

            Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")

In the above SwiftUI program, we have set the lineSpacing() modifier to a Text view.

Well, you can also set the lineSpacing() modifier to the parent view and it will affect all the text views inside the parent view. In the example below we have two text views in the parent view VStack:

        VStack {
            Text("Some text...")
            Text("Some text...")

When you test the above code, you can see that the spacing amount set by using lineSpacing() works for both the Text views. But between the two text view, there is no line spacing. Well, this problem can be solved by using Spacer or padding.