gpt4 book ai didi

react-native - 有没有办法在 React Native 中全局设置字体?

转载 作者:行者123 更新时间:2023-12-03 23:29:49 27 4
gpt4 key购买 nike

我需要创建一个适用于每个 Text 的自定义字体整个应用程序中的组件。
有没有办法在 React Native 中全局设置字体?

最佳答案

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

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

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

另一种方法是定义一个样式对象并在您想要的任何地方使用它。

关于react-native - 有没有办法在 React Native 中全局设置字体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51023593/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com