#鸿蒙学习大百科#如何通过属性字符串实现文本基线偏移效果?

如何通过属性字符串实现文本基线偏移效果?

HarmonyOS
2024-10-26 09:50:15
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
自封的不算
import { LengthMetrics } from '@kit.ArkUI';

@Entry
@Component
struct Index {
  mutableStyledString: MutableStyledString = new MutableStyledString("运动35分钟", [
    {
      start: 0,
      length: 3,
      styledKey: StyledStringKey.BASELINE_OFFSET,
      styledValue: new BaselineOffsetStyle(LengthMetrics.px(20))
    }
  ]);
  controller: TextController = new TextController();

  async onPageShow() {
    this.controller.setStyledString(this.mutableStyledString)
  }

  build() {
    Column() {
      // 显示属性字符串
      Text(undefined, { controller: this.controller })
    }
    .width('100%')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
分享
微博
QQ
微信
回复
2024-10-26 16:49:47


相关问题
#鸿蒙学习大百科#如何实现ui优化?
965浏览 • 1回复 待解决