有一个text固定大小,期望文字显示不要超出text范围该怎么处理?
@Entry
@Component
struct TextExample {
@State mT: string =
'元服务是一种轻量程序形态,有独立入口、免安装,以万能卡片等多种呈现形态,为用户提供便捷、轻量化服务;它可独立上架、分发、运行,助力你轻松实现业务闭环。'
build() {
Stack() {
Row() {
Text(this.mT)
.width(100)
.height(100)
.fontColor(Color.Black)
.fontSize(13)
.margin({ left: 20, top: 50 })
.backgroundColor('#3300ff00')
}
.width('100%')
.height(200)
.backgroundColor('#33ff0000')
.justifyContent(FlexAlign.Start)
.alignItems(VerticalAlign.Top)
}.width('100%').height('100%')
}
}
可以给文本设置一个最大行数或者可以设置一个省略文字,详情请参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-text-V5\#子组件