• HarmonyOS/OpenHarmony原生应用-ArkTS万能卡片组件Span


    作为Text组件的子组件,用于显示行内文本的组件。子组件

    一、接口

    Span(value: string | Resource)

    从API version 9开始,该接口支持在ArkTS卡片中使用。

    参数:

    参数名

    参数类型

    必填

    参数描述

    value

    string | Resource

    文本内容

    二、属性

    通用属性方法仅支持通用文本样式

    名称

    参数类型

    描述

    decoration

    {

    type: TextDecorationType,

    color?: ResourceColor

    }

    设置文本装饰线样式及其颜色。

    默认值:{

    type: TextDecorationType.None

    color:Color.Black

    }

    从API version 9开始,该接口支持在ArkTS卡片中使用。

    letterSpacing

    number | string

    设置文本字符间距。取值小于0,字符聚集重叠,取值大于0且随着数值变大,字符间距越来越大,稀疏分布。

    从API version 9开始,该接口支持在ArkTS卡片中使用。

    textCase

    TextCase

    设置文本大小写。

    默认值:TextCase.Normal

    从API version 9开始,该接口支持在ArkTS卡片中使用。

    三、事件

    通用事件仅支持点击事件

    说明

    由于Span组件无尺寸信息,因此点击事件返回的ClickEvent对象的target属性无效。

    四、示例

    // xxx.ets

    @Entry

    @Component

    struct SpanExample {

      build() {

        Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) {

          Text('Basic Usage').fontSize(9).fontColor(0xCCCCCC)

          Text() {

            Span('In Line')

            Span(' Component')

            Span(' !')

          }

          Text() {

            Span('This is the Span component').fontSize(12).textCase(TextCase.Normal)

              .decoration({ type: TextDecorationType.None, color: Color.Red })

          }

          // 文本横线添加

          Text('Text Decoration').fontSize(9).fontColor(0xCCCCCC)

          Text() {

            Span('I am Underline-span').decoration({ type: TextDecorationType.Underline, color: Color.Red }).fontSize(12)

          }

          Text() {

            Span('I am LineThrough-span')

              .decoration({ type: TextDecorationType.LineThrough, color: Color.Red })

              .fontSize(12)

          }

          Text() {

            Span('I am Overline-span').decoration({ type: TextDecorationType.Overline, color: Color.Red }).fontSize(12)

          }

          // 文本字符间距

          Text('LetterSpacing').fontSize(9).fontColor(0xCCCCCC)

          Text() {

            Span('span letter spacing')

              .letterSpacing(0)

              .fontSize(12)

          }

          Text() {

            Span('span letter spacing')

              .letterSpacing(-2)

              .fontSize(12)

          }

          Text() {

            Span('span letter spacing')

              .letterSpacing(3)

              .fontSize(12)

          }

          // 文本大小写展示设置

          Text('Text Case').fontSize(9).fontColor(0xCCCCCC)

          Text() {

            Span('I am Lower-span').fontSize(12)

              .textCase(TextCase.LowerCase)

              .decoration({ type: TextDecorationType.None })

          }

          Text() {

            Span('I am Upper-span').fontSize(12)

              .textCase(TextCase.UpperCase)

              .decoration({ type: TextDecorationType.None })

          }

        }.width('100%').height(250).padding({ left: 35, right: 35, top: 35 })

      }

    }

    五、场景

    适合做文本特效的各种卡片

    本文根据HarmonyOS官方文档整理

  • 相关阅读:
    VMware 虚拟机中 Linux 系统Centos7磁盘空间扩容
    ​​​​​​​ARCGIS API for Python进行城市区域提取
    torch_vision(二):模型和预训练weight模块 torchvision.models
    云洲智能IPO被终止:年营收2.5亿亏1.3亿 曾拟募资15.5亿
    kafka消费/发送消息,消息过大报错解决whose size is larger than the fetch size 1048576
    #循循渐进学51单片机#函数进阶与按键#not.7
    Webpack5基础笔记一
    ChatGPT-GPT4:将AI技术融入科研、绘图与论文写作的实践
    vscode 安装leetcode 插件
    深度学习与总结JVM专辑(一):基础介绍&&内存结构(图文+代码)
  • 原文地址:https://blog.csdn.net/weixin_69135651/article/details/133668963