Contents

AttributeScopes.SwiftUIAttributes.BaselineOffsetAttribute

A key for the distance a run of attributed text shifts from its baseline.

Declaration

@frozen enum BaselineOffsetAttribute

Overview

A positive value raises the run and a negative value lowers it, which lets you set a unit or a footnote marker above the surrounding text:

var measure = AttributedString("12 m")
if let unit = measure.range(of: "m") {
    measure[unit].baselineOffset = 6
}

Text(measure)

Shifting a run does not change the height of the line, so a large offset can push text into the line above or below.