WebView React Native中的自定义字体

时间:2017-12-13 11:50:18

标签: android react-native fonts

我使用WebView来显示一些正确理由的文字(Android不支持理由)。我在WebView文字style中尝试应用自定义字体时已经筋疲力尽了。我已尝试过以下代码,但没有结果:

var html = `<h1 style="font-family: MyFont"> some text here </h1>`
<WebView
  source={{html}}
  style={{width: 200, height: 200}}
/>

这是我的react native文件结构:

Project
  -android
  -node_modules 
  -...
  -assets
   --fonts
    ---MyFont.ttf

MyFont.ttf位于Project/assets/fonts/内。我也试过了this,但无法让它发挥作用。它说我应该设置baseUrl,但我不知道要设置url。请帮助我,我真的需要一个全面而有效的例子。

0 个答案:

没有答案