OneScript

font

Set an inheritable semantic or fixed-size font.

font(value) accepts a value created by Font. A view without this modifier inherits the surrounding SwiftUI font and Dynamic Type behavior.

import { Font, FontDesign, FontWeight, Modifier, Text, VStack } from "onescript/views"

<VStack modifier={Modifier.font(Font.body)}>
  <Text modifier={Modifier.font(Font.headline)}>Title</Text>
  <Text>Content</Text>
</VStack>

Semantic fonts

Semantic fonts automatically follow the user's Dynamic Type setting.

ValueSwiftUI font
Font.largeTitle.largeTitle
Font.title.title
Font.title2.title2
Font.title3.title3
Font.headline.headline
Font.subheadline.subheadline
Font.body.body
Font.callout.callout
Font.footnote.footnote
Font.caption.caption
Font.caption2.caption2

Fixed-size system font

Use Font.system(options) when a layout requires an exact size in pt. It accepts size, optional weight, and optional design. Fixed-size system fonts do not scale with Dynamic Type.

<Text modifier={Modifier.font(Font.system({ size: 16, weight: FontWeight.semibold, design: FontDesign.rounded }))}>
  Fixed-size text
</Text>

The size must be a positive finite number. Invalid values throw an error.

How is this guide?

Last updated on

On this page