有没有办法在react native中全局设置字体? [英] Is there is way to set a font globally in react native?

查看:608
本文介绍了有没有办法在react native中全局设置字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以在react native中全局设置字体? 我需要做的是在整个应用程序中应用每个Text组件的自定义字体. 非常感谢您的帮助,谢谢

Is there is a way to set a font globally in react native? what I need to do is a custom font that applies every Text component in the whole application. Your help is extremely appreciated, Thanks

推荐答案

一种方法是为RN Text说MyTextCustomFont创建包装器:

One way is to create a wrapper for RN Text say MyTextCustomFont:

const MyTextCustomFont = (props) => {
   return (
        <Text style={{fontFamily:'myFont'}} {...props} >{props.children}</Text>
   )
}

导入此MyTextCustomFont并在任何地方使用.

import this MyTextCustomFont and use anywhere.

另一种方法是定义样式对象,然后在任何需要的地方使用它.

Another way is to define a style object and use it wherever you want.

这篇关于有没有办法在react native中全局设置字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆