请参考以下示例:// xxx.ets import { MeasureText } from '@kit.ArkUI'; @Entry @Component struct WebComponent { @State newsINfo:string = '测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试出生时是菜市场是市场上' boxHeight:number = 80 textSize : SizeOptions = MeasureText.measureTextSize({ textContent: this.newsINfo, fontSize: '15px' }) build() { Column() { Row(){ Text(this.newsINfo) .backgroundColor(Color.Green) .textOverflow({overflow:TextOverflow.Clip}) .width('100%') .height('100%') .fontSize(15) .maxLines(Math.floor(this.boxHeight/Number(this.textSize.height))) } .width(150) .height(this.boxHeight) .backgroundColor(Color.Brown) } } }
请参考以下示例: