W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎勵
本模塊提供文本寬度、高度等相關(guān)計(jì)算。
本模塊首批接口從API version 9開始支持。后續(xù)版本的新增接口,采用上角標(biāo)單獨(dú)標(biāo)記接口的起始版本。
measureText(options: MeasureOptions): number
計(jì)算指定文本單行布局下的寬度。
系統(tǒng)能力: SystemCapability.ArkUI.ArkUI.Full
參數(shù):
參數(shù)名 | 類型 | 必填 | 說明 |
---|---|---|---|
options | 是 | 被計(jì)算文本描述信息。 |
返回值:
類型 | 說明 |
---|---|
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%')
- }
- }
被計(jì)算文本屬性。
系統(tǒng)能力: SystemCapability.ArkUI.ArkUI.Full
名稱 | 類型 | 必填 | 說明 |
---|---|---|---|
textContent | string | 是 | 設(shè)置被計(jì)算文本內(nèi)容。 |
fontSize | number | string | Resource | 否 | 設(shè)置被計(jì)算文本字體大小,fontSize為number類型時(shí),使用fp單位。 默認(rèn)值:16fp。 **說明:**不支持設(shè)置百分比字符串。 |
fontStyle | number | FontStyle | 否 | 設(shè)置被計(jì)算文本字體樣式。 默認(rèn)值:FontStyle.Normal |
fontWeight | number | string | FontWeight | 否 | 設(shè)置被計(jì)算文本的字體粗細(xì),number類型取值[100, 900],取值間隔為100,默認(rèn)為400,取值越大,字體越粗。string類型僅支持number類型取值的字符串形式,例如"400",以及"bold"、"bolder"、"lighter"、"regular"、"medium",分別對應(yīng)FontWeight中相應(yīng)的枚舉值。 默認(rèn)值:FontWeight.Normal |
fontFamily | string | Resource | 否 | 設(shè)置被計(jì)算文本字體列表。默認(rèn)字體'HarmonyOS Sans',且當(dāng)前只支持這種字體。 |
letterSpacing | number | string | 否 | 設(shè)置被計(jì)算文本字符間距。 |
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: