鸿蒙UI界面——@ohos.measure (文本计算)

电子说

1.2w人已加入

描述

导入模块

 

import measure from '@ohos.measure'

 

measure.measureText

measureText(options: MeasureOptions): number

计算指定文本单行布局下的宽度。

系统能力: SystemCapability.ArkUI.ArkUI.Full

参数:

 

参数名 类型 必填 说明
options MeasureOptions 被计算文本描述信息。

 

返回值:

 

类型 说明
number 文本宽度。说明: 单位px。

 

示例:

 

import measure from '@ohos.measure' @Entry @Component struct Index { @State message: string = 'Hello World' @State textWidth : number = measure.measureText({ textContent: "Hello word", fontSize: '50px' }) build() { Row() { Column() { Text("The width of 'Hello World': " + this.textWidth) } .width('100%') } .height('100%') } }

 

MeasureOptions

被计算文本属性。

系统能力: SystemCapability.ArkUI.ArkUI.Full

ui



审核编辑 黄宇


 

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分