I want to add character spacing in the text of SwiftUI in iOS version iOS 14 and plus.
When I use a new modifier called as kerning and Tracking after applying fonts styling then it won't work. So any pointer will be appreciated.
kerning
and tracking
are available in earlier versions of iOS, but only if they're applied directly to Text
views.
What's new in iOS 16 is the ability to apply the modifier to any view, and have it apply to any of its Text child views.
Note the availability flags for Text.tracking
vs View.tracking
:
Text.tracking(_:)
- iOS 13.0+, macOS 10.15+View.tracking(_:)
- iOS 16.0+, macOS 13.0+So that means that this should work for you in iOS 14:
Text("My Sample Text")
.tracking(-0.1)
but this would not:
VStack {
Text("My Sample View")
Text("With two lines of text")
}
.tracking(-0.1)