In SwiftUI, there are two modifiers available that can be used to add spacing between letters in SwiftUI text for text view. You can increase or decrease the spacing amount between characters of a text.
The modifiers I have just discussed are
tracking() modifier simply adds or changes the spacing between all the characters of the text display using TextView. No matter what, space will be added between each letter. This is because it ignores the ligatures.
Below is an example of using
The above program will add spacing of 45 between characters of the text view text “fli”. Here 45 is the amount of spacing.
To confirm that it also changes space in ligature, below is the given code:
Text("fli") .font(.custom("AmericanTypewriter", size: 35)) .tracking(45)
kerning() modifier also can change the spacing amount. But it doesn’t ignore the ligatures. The
kerning() skip adding spacing for ligatures. Below is given an example:
Text("fli") .font(.custom("AmericanTypewriter", size: 35)) .kerning(45)
Now if we test the above code, it will not change the space between “fl”, but space will be added between “li”. This is because “fl” form a ligature. In our example, we have added the font “AmericanTypewriter”. This is because of the fact that the “fl” form a ligature in this font.