Declaration
compose().baselineOffset(baselineOffset: number)nonisolated func baselineOffset(_ baselineOffset: CGFloat) -> TextParameters
baselineOffset*numberThe amount to shift the text vertically (up or down) relative to its baseline.
Return value
Text that's above or below its baseline.
Discussion
Change the baseline offset to move the text in the view (in points) up or down relative to its baseline. The bounds of the view expand to contain the moved text.
HStack(alignment: .top) {
Text("Hello")
.baselineOffset(-10)
.border(Color.red)
Text("Hello")
.border(Color.green)
Text("Hello")
.baselineOffset(10)
.border(Color.blue)
}
.background(Color(white: 0.9))By drawing a border around each text view, you can see how the text moves, and how that affects the view.
The first view, with a negative offset, grows downward to handle the
lowered text. The last view, with a positive offset, grows upward. The
enclosing HStack instance, shown in gray, ensures all the text views
remain aligned at their top edge, regardless of the offset.
See also
More in Text modifiers.
- accessibilityHeadingSets the accessibility level of this heading.
- accessibilityLabelAdds a label to the view that describes its contents.
- accessibilityTextContentTypeSets an accessibility text content type.
- boldApplies a bold font weight to the text.
- fontSets the default font for text in the view.
- fontDesignSets the font design of the text.
- fontWeightSets the font weight of the text.
- fontWidthSets the font width of the text.
- foregroundStyleSets the style of the text displayed by this view.
- italicApplies italics to the text.
- kerningSets the spacing, or kerning, between characters.
- monospacedModifies the font of the text to use the fixed-width variant of the current font, if possible.