A component that draws 2D text at an entity's location.
`TextComponent` renders two-dimensional text in a RealityKit scene.
It creates a rounded rectangle mesh to serve as a canvas and draws an attributed string on the mesh. This component handles
everything required to render the text, including updating the plane transform, setting material parameters, and creating mesh components.
Set the component's ``size`` to define the area of the canvas in points. This setting also affects the size at which RealityKit
renders the text. The world-size of the canvas may be different than the value you specify because the component's entity inherits its
parent's transform, which may include scale changes that affect the final rendered size.
Text components use the CoreGraphics coordinate space: The origin is at the upper left of the canvas and positive
values extend down and to the right. You can't specify an explicit backing-buffer size. RealityKit dynamically adjusts
the backing size to a value that results in high-fidelity text at its current location.
RealityKit lays out text using default ``Foundation/AttributedString`` behaviors and wraps text instead of
truncating it. It keeps the text a constant font size: It doesn't stretch or scale the text to fit the canvas. Use
Core Text to determine the required canvas size for a particular string or layout.
Members (9)
get · iOS 18.0+
cornerRadius
TypeScript
get cornerRadius(): number
Swift declaration
var cornerRadius: Float
The corner radius of the text mesh.
The corner geometry is based on a circular shape and is not a continuous corner. Text components use the CoreGraphics
coordinate space: The origin is at the upper left of the canvas and positive values extend down and to the right.
set · iOS 18.0+
cornerRadius
TypeScript
set cornerRadius(value: number)
Swift declaration
var cornerRadius: Float
The corner radius of the text mesh.
The corner geometry is based on a circular shape and is not a continuous corner. Text components use the CoreGraphics
coordinate space: The origin is at the upper left of the canvas and positive values extend down and to the right.
get · iOS 18.0+
backgroundColor
TypeScript
get backgroundColor(): (_CoreGraphics_CGColor) | null
Swift declaration
var backgroundColor: CGColor?
The canvas's background color.
Specify a color to have RealityKit render the entire canvas in a color. The specified value may include an alpha component.
By default, the canvas is transparent.
set · iOS 18.0+
backgroundColor
TypeScript
set backgroundColor(value: (_CoreGraphics_CGColor) | null)
Swift declaration
var backgroundColor: CGColor?
The canvas's background color.
Specify a color to have RealityKit render the entire canvas in a color. The specified value may include an alpha component.
By default, the canvas is transparent.
get · iOS 18.0+
size
TypeScript
get size(): { width: number; height: number }
Swift declaration
var size: CGSize { get set }
The size of the canvas in points.
Defaults to `CGSize.zero`. This defines both how large the canvas is for text layout, as well as how
large it is in world-space. The canvas coordinate system uses the standard CoreGraphics / CoreText
coordinate space. There is no explicit backing-buffer size, as it might be dynamic to generate high-fidelity
text. The canvas size uses points as 1/72nd of an inch (about 0.352 mm) in world-space. World-size
might change as a function of any peer or parent transform component.
This component lays out text using default `AttributedString` behaviors, but respecting
the `edgeInsets` property. Text will wrap-around, rather than truncate. It will stay at the
given fixed font size, and will not stretch or scale to fit. CoreText can determine the
required canvas size for a particular string or layout. The canvas size is clamped to a maximum
of 2048 points in width and height.
set · iOS 18.0+
size
TypeScript
set size(value: { width: number; height: number })
Swift declaration
var size: CGSize { get set }
The size of the canvas in points.
Defaults to `CGSize.zero`. This defines both how large the canvas is for text layout, as well as how
large it is in world-space. The canvas coordinate system uses the standard CoreGraphics / CoreText
coordinate space. There is no explicit backing-buffer size, as it might be dynamic to generate high-fidelity
text. The canvas size uses points as 1/72nd of an inch (about 0.352 mm) in world-space. World-size
might change as a function of any peer or parent transform component.
This component lays out text using default `AttributedString` behaviors, but respecting
the `edgeInsets` property. Text will wrap-around, rather than truncate. It will stay at the
given fixed font size, and will not stretch or scale to fit. CoreText can determine the
required canvas size for a particular string or layout. The canvas size is clamped to a maximum
of 2048 points in width and height.
get · iOS 18.0+
text
TypeScript
get text(): (_Foundation_AttributedString) | null
Swift declaration
var text: AttributedString?
The attributed string this component renders.
RealityKit renders text centered vertically. Neither the length of the string nor the specified attributes affect
the size of the canvas mesh. All attributes are supported except for `TextAlignment` and `StrikethroughStyle`.
set · iOS 18.0+
text
TypeScript
set text(value: (_Foundation_AttributedString) | null)
Swift declaration
var text: AttributedString?
The attributed string this component renders.
RealityKit renders text centered vertically. Neither the length of the string nor the specified attributes affect
the size of the canvas mesh. All attributes are supported except for `TextAlignment` and `StrikethroughStyle`.