如何拿到文本框文字的宽度数值

如何拿到文本框文字的宽度数值

HarmonyOS
2024-07-24 10:33:11
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
怎么不算呢

主要使用measureText计算

import { MeasureText } from '@kit.ArkUI';

@Entry
@Component
struct Index {
  @State message: string = 'Hello World'
  @State textWidth: number = MeasureText.measureText({
    textContent: "Hello word",
    fontSize: '50px'
  })

  build() {
    Row() {
      Column() {
        Text("The width of 'Hello World': " + this.textWidth)
      }
      .width('100%')
    }
    .height('100%')
  }
}
分享
微博
QQ
微信
回复
2024-07-24 19:45:35
提问
该提问已有0人参与 ,帮助了0人