UI通用修饰符
font
设置可继承的语义字体或固定字号字体。
font(value) 接受 Font 创建的值。没有该 Modifier 的视图会继承外层 SwiftUI 字体及其 Dynamic Type 行为。
import { Font, FontDesign, FontWeight, Modifier, Text, VStack } from "onescript/views"
<VStack modifier={Modifier.font(Font.body)}>
<Text modifier={Modifier.font(Font.headline)}>标题</Text>
<Text>正文</Text>
</VStack>语义字体
语义字体会自动响应用户的 Dynamic Type 设置。
| 值 | SwiftUI 字体 |
|---|---|
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 |
固定字号系统字体
布局需要精确字号时使用 Font.system(options),其中包含单位为 pt 的 size、可选 weight 和可选 design。固定字号系统字体不会随 Dynamic Type 缩放。
<Text modifier={Modifier.font(Font.system({ size: 16, weight: FontWeight.semibold, design: FontDesign.rounded }))}>
固定字号文本
</Text>字号必须是有限正数,无效值会抛出异常。
How is this guide?
最后更新于