docs/api/dom/unitextelement.md
text 组件的 DOM 元素对象。
| Web | 微信小程序 | Android | iOS | iOS uni-app x UTS 插件 | HarmonyOS | HarmonyOS(Vapor) |
|---|---|---|---|---|---|---|
| 4.0 | x | 4.0 | 4.11 | 4.25 | 4.61 | 5.0 |
graph LR
UniTextElement -- Extends --> UniElement
style UniElement color:#42b983
click UniElement "https://doc.dcloud.net.cn/uni-app-x/api/dom/unielement.html"
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| value | string | 是 | - | Web: x; 微信小程序: x; Android: 4.0; iOS: 4.11; iOS uni-app x UTS 插件: 4.25; HarmonyOS: 4.61; HarmonyOS(Vapor): 5.0 | 只读属性 text元素的文案内容 |
设置文本内容
| Web | 微信小程序 | Android | iOS | iOS uni-app x UTS 插件 | HarmonyOS | HarmonyOS(Vapor) |
|---|---|---|---|---|---|---|
| x | x | 4.81 | x | x | x | x |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| layout | UniTextLayout | 是 | - | Web: x; 微信小程序: x; Android: -; iOS: x; HarmonyOS: x | 文本对象 |
setText 设置文本
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| x | x | 4.81 | x | x |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| text | string | 是 | - | Web: x; 微信小程序: x; Android: -; iOS: x; HarmonyOS: x |
setColor 设置文本颜色
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| x | x | 4.81 | x | x |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| color | string | 是 | - | Web: x; 微信小程序: x; Android: -; iOS: x; HarmonyOS: x |
setFontFamily 设置字体名称
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| x | x | 4.81 | x | x |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| family | string | 是 | - | Web: x; 微信小程序: x; Android: -; iOS: x; HarmonyOS: x |
setFontSize 设置字体大小
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| x | x | 4.81 | x | x |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| size | string | 是 | - | Web: x; 微信小程序: x; Android: -; iOS: x; HarmonyOS: x |
setFontStyle 设置字体样式
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| x | x | 4.81 | x | x |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| style | string | 是 | - | Web: x; 微信小程序: x; Android: -; iOS: x; HarmonyOS: x |
setFontWeight 设置字体粗细
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| x | x | 4.81 | x | x |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| weight | string | 是 | - | Web: x; 微信小程序: x; Android: -; iOS: x; HarmonyOS: x |
setLineHeight 设置行高
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| x | x | 4.81 | x | x |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| height | string | 是 | - | Web: x; 微信小程序: x; Android: -; iOS: x; HarmonyOS: x |
setTextAlign 设置文字水平对齐方式
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| x | x | 4.81 | x | x |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| align | string | 是 | - | Web: x; 微信小程序: x; Android: -; iOS: x; HarmonyOS: x |
setTextOverflow 设置文字溢出裁剪方式
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| x | x | 4.81 | x | x |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| overflow | string | 是 | - | Web: x; 微信小程序: x; Android: -; iOS: x; HarmonyOS: x |
setTextShadow 设置文字阴影
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| x | x | 4.81 | x | x |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| shadow | string | 是 | - | Web: x; 微信小程序: x; Android: -; iOS: x; HarmonyOS: x |
setTextDecorationLine 设置文本修饰类型
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| x | x | 4.81 | x | x |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| decorationLine | string | 是 | - | Web: x; 微信小程序: x; Android: -; iOS: x; HarmonyOS: x |
setWhiteSpace 设置处理空白字符
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| x | x | 4.81 | x | x |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| whiteSpace | string | 是 | - | Web: x; 微信小程序: x; Android: -; iOS: x; HarmonyOS: x |
append 添加子文本对象
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| x | x | 4.81 | x | x |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| layout | UniTextLayout | 是 | - | Web: x; 微信小程序: x; Android: -; iOS: x; HarmonyOS: x | 文本对象 |
measure 测量文本大小
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| x | x | 4.81 | x | x |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| constraint | UniLayoutConstraintSize | 是 | - | Web: x; 微信小程序: x; Android: -; iOS: x; HarmonyOS: x | 布局约束大小 |
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| minWidth | number | 否 | - | Web: x; 微信小程序: x; Android: 4.81; iOS: x; HarmonyOS: x | 元素最小宽度,逻辑像素值 |
| 可选值,不设置则认为没有最小宽度 | |||||
| maxWidth | number | 否 | - | Web: x; 微信小程序: x; Android: 4.81; iOS: x; HarmonyOS: x | 元素最大宽度,逻辑像素值 |
| 可选值,不设置则认为可以无限宽 | |||||
| minHeight | number | 否 | - | Web: x; 微信小程序: x; Android: 4.81; iOS: x; HarmonyOS: x | 元素最小高度,逻辑像素值 |
| 可选值,不设置则认为没有最小高度 | |||||
| maxHeight | number | 否 | - | Web: x; 微信小程序: x; Android: 4.81; iOS: x; HarmonyOS: x | 元素最大高度,逻辑像素值 |
| 可选值,不设置则认为可以无限高 |
| 类型 | 描述 |
|---|---|
| UniLayoutSize | 布局大小 |
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| width | number | 是 | - | Web: x; 微信小程序: x; Android: 4.81; iOS: x; HarmonyOS: x | 元素宽度,逻辑像素值 |
| height | number | 是 | - | Web: x; 微信小程序: x; Android: 4.81; iOS: x; HarmonyOS: x | 元素高度,逻辑像素值 |
获取内容宽高
| Web | 微信小程序 | Android | iOS | iOS uni-app x UTS 插件 | HarmonyOS | HarmonyOS(Vapor) |
|---|---|---|---|---|---|---|
| x | x | 4.81 | x | x | x | x |
| 类型 | 描述 |
|---|---|
| UniLayoutSize | 布局大小 |
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| width | number | 是 | - | Web: x; 微信小程序: x; Android: 4.81; iOS: x; HarmonyOS: x | 元素宽度,逻辑像素值 |
| height | number | 是 | - | Web: x; 微信小程序: x; Android: 4.81; iOS: x; HarmonyOS: x | 元素高度,逻辑像素值 |