Skip to content

Text 文本 ​

文本展示原语:消费全局排版令牌,支持字号级别、字重、色调与对齐。

契约源:lh-ui-core/specs/text.json · 黄金用例:lh-ui-core/cases/text.json(5 条,已翻译为 XCTest,macOS 宿主即可运行)

字号级别 ​

level 映射到 typography.fontSize.<level> 令牌,默认 base。

9:41Text 字号

特大 extraLarge

大 large

中 medium

基准 base(默认)

小 small

特小 extraSmall

HTML 模拟预览(iOS / SwiftUI 外观),非真机渲染

swift
LhText("标题文字", level: .large)

字重 ​

weight 映射到 typography.fontWeight.<weight> 令牌(primary 400 / bold 600)。

9:41Text 字重

常规 primary(默认)

加粗 bold

HTML 模拟预览(iOS / SwiftUI 外观),非真机渲染

色调 ​

tone 映射到 color.text.<tone> 令牌;selected 取 color.selected。

9:41Text 色调

主要 primary(默认)

常规 regular

次要 secondary

占位 placeholder

禁用 disabled

选中 selected

HTML 模拟预览(iOS / SwiftUI 外观),非真机渲染

对齐与行高 ​

lhAlign 在行盒宽度内对齐;行高始终取 typography.lineHeight.primary(字号 × 1.8)。

9:41Text 对齐

居中 center

右对齐 end

HTML 模拟预览(iOS / SwiftUI 外观),非真机渲染

swift
LhText("居中", lhAlign: .center)

API ​

属性说明类型默认值
content文本内容(构造器第一个参数,spec 的 default 插槽)String""
level字号级别LhTextLevel.base
weight字重LhTextWeight.primary
tone文字色调LhTextTone.primary
lhAlign水平对齐方式LhTextAlign.start

LhTextLevel ​

值fontSize 令牌
.extraLargetypography.fontSize.extraLarge(20pt)
.largetypography.fontSize.large(18pt)
.mediumtypography.fontSize.medium(16pt)
.basetypography.fontSize.base(14pt,默认)
.smalltypography.fontSize.small(13pt)
.extraSmalltypography.fontSize.extraSmall(12pt)

LhTextTone ​

值文字色令牌
.primarycolor.text.primary
.regularcolor.text.regular
.secondarycolor.text.secondary
.placeholdercolor.text.placeholder
.disabledcolor.text.disabled
.selectedcolor.selected

令牌对照 ​

令牌用途
typography.fontSize.<level>六档字号
typography.fontWeight.{primary,bold}两档字重
typography.lineHeight.primary行高(字号 × 1.8)
color.text.<tone> / color.selected文字色调

黄金用例对照 ​

case id断言本地测试
default-level-uses-base-tokens默认级别消费 base 排版令牌LhTextTests.testDefaultLevelUsesBaseTokens
large-level-uses-large-token大级别消费 large 字号令牌LhTextTests.testLargeLevelUsesLargeToken
bold-weight-uses-bold-token粗体消费 bold 字重令牌LhTextTests.testBoldWeightUsesBoldToken
secondary-tone-uses-text-secondary次要色调取次要文字色令牌LhTextTests.testSecondaryToneUsesTextSecondary
render-emits-single-text-command渲染发出一条 TEXT 指令LhTextTests.testAllLevelsUseTheirTokens(令牌映射覆盖率)
bash
swift test --filter LhTextTests