1 Star 0 Fork 5.2K

OpenHarmony-build / docs

forked from OpenHarmony / docs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ts-universal-attributes-text-style.md 10.54 KB
一键复制 编辑 原始数据 按行查看 历史
zengyawen 提交于 2021-11-10 20:02 . add arkui

文本样式设置

针对包含文本元素的组件,设置文本样式。

名称

参数类型

默认值

描述

fontColor

Color

-

设置文本颜色。

fontSize

Length

-

设置文本尺寸,Length为number类型时,使用fp单位。

fontStyle

FontStyle

Normal

设置文本的字体样式。

fontWeight

number | FontWeight

Normal

设置文本的字体粗细,number类型取值[100, 900],取值间隔为100,默认为400,取值越大,字体越粗。

提供常用枚举值,参考:FontWeight

fontFamily

string

-

设置文本的字体列表。使用多个字体,使用','进行分割,优先级按顺序生效。例如:'Arial, sans-serif'。

  • FontStyle枚举说明

    名称

    描述

    Normal

    标准的字体样式。

    Italic

    斜体的字体样式。

  • FontWeight枚举说明

    名称

    描述

    Lighter

    字体较细。

    Normal

    字体粗细正常。

    Regular

    字体粗细正常。

    Medium

    字体粗细适中。

    Bold

    字体较粗。

    Bolder

    字体非常粗。

示例

@Entry
@Component
struct TextStyleExample {
  build() {
    Column({ space: 5 }) {
      Text('default text')

      Text('text font color red')
        .fontColor(Color.Red)

      Text('text font size 20')
        .fontSize(20)

      Text('text font style Italic')
        .fontStyle(FontStyle.Italic)

      Text('text fontWeight bold')
        .fontWeight(700)

      Text('text fontFamily sans-serif')
        .fontFamily('sans-serif')

      Text('red 20 Italic bold cursive text')
        .fontColor(Color.Red)
        .fontSize(20)
        .fontStyle(FontStyle.Italic)
        .fontWeight(700)
        .fontFamily('cursive')
        .textAlign(TextAlign.Center)
        .width('90%')

      Text('Orange 18 Normal source-sans-pro text')
        .fontColor(Color.Orange)
        .fontSize(18)
        .fontStyle(FontStyle.Normal)
        .fontWeight(400)
        .fontFamily('source-sans-pro,cursive,sans-serif')
    }.width('100%')
  }
}

1
https://gitee.com/openharmony-build/docs.git
git@gitee.com:openharmony-build/docs.git
openharmony-build
docs
docs
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891