HarmonyOS 如何应用手机中应用的沙箱目录的字体?

如题:HarmonyOS 如何应用手机中应用的沙箱目录的字体?

阅读 377
1 个回答

参考如下demo:

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

@Entry
@Component
struct Index {
  @State message: string = 'Hello World';

  aboutToAppear(): void{
    try {
      let dest = getContext().filesDir + '/iconfont.ttf';
      font.registerFont({
        familyName: 'custom',
        familySrc: 'file://' + dest,
      })
    } catch (e){
      console.error('error' + JSON.stringify(e))
    }
  }
  build() {
    Row() {
      Column() {
        Text('自定义字体')
          .fontSize(50)
          .fontFamily('custom')
          .fontWeight(FontWeight.Bold)
      }
      .width('100%')
    }
    .height('100%')
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进