Skip to main content
.layoutPriority(priority: number): Component
priority
number
required
The layout priority. Higher values receive preference for available space. Default is 0.

Support

Usage

Prioritizing one text over another

When two texts compete for space in an HStack, the one with higher layout priority gets its full width before the other.
HStack([
    Text("This text should get more space")
        .layoutPriority(1),
    Text("Secondary text")
])

Preventing truncation

HStack([
    Text("Important label")
        .layoutPriority(1)
        .lineLimit(1),
    Spacer(),
    Text("$99.99")
        .layoutPriority(1)
        .lineLimit(1)
])

Notes

  • Layout priority only matters when sibling components compete for limited space within a parent container (e.g., HStack, VStack).
  • All components default to a priority of 0. A component with priority 1 will be offered its ideal size before components with priority 0.
  • Negative values are valid and will cause the component to shrink before siblings.

See Also

  • fixedSize — prevents a component from being resized along specified axes
  • frame — sets explicit size constraints