参考如下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%') } }
参考如下demo: