中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
如何获取文本框里的文字宽度
微信扫码分享
使用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%') } }
参考链接:
文本计算
使用measureText计算指定文本单行布局的宽度。
代码示例
参考链接:
文本计算