tracking

Sets the tracking for the text.

Text ModifieriOS 13.0+macOS 10.15+tvOS 13.0+watchOS 6.0+tracking(_:) in SwiftUI

Declaration

React
compose().tracking(tracking: number)
Swift
nonisolated func tracking(_ tracking: CGFloat) -> Text

Parameters

  • tracking*number

    The amount of additional space, in points, that the view should add to each character cluster after layout. Value of 0 sets the tracking to the system default value.

Return value

Text with the specified amount of tracking.

Discussion

Tracking adds space, measured in points, between the characters in the text view. A positive value increases the spacing between characters, while a negative value brings the characters closer together.

VStack(alignment: .leading) {
    Text("ABCDEF").tracking(-3)
    Text("ABCDEF")
    Text("ABCDEF").tracking(3)
}

The code above uses an unusually large amount of tracking to make it easy to see the effect.

The effect of tracking resembles that of the Text.kerning(_:) modifier, but adds or removes trailing whitespace, rather than changing character offsets. Also, using any nonzero amount of tracking disables nonessential ligatures, whereas kerning attempts to maintain ligatures.

See also

More in Text modifiers.