繁体   English   中英

React-Native Button 中的自定义字体

[英]Custom font in React-Native Button

如何为 ReactNative 按钮使用自定义 FontFamily? 这是按钮:

 <Button
      title="ACCEDI"
      color={"#008800"}
      marginVertial={10}
      fontFamily={Fonts.Montserrat}
 />

但这不起作用,fontFamily 没有改变。 我该如何改变它?

请尝试将其放入样式属性中:

textStyle={{fontFamily: Fonts.Montserrat}}

要么

titleStyle={{fontFamily: Fonts.Montserrat}}

以下是有用的链接:

https://medium.com/react-native-training/react-native-custom-fonts-ccc9aacf9e5e

https://github.com/react-native-training/react-native-elements/issues/977

尝试使用此链接作为React Native 中的参考自定义字体

编辑 package.json 中的字体文件夹 src 并尝试此链接。

我不认为你可以设置字体系列。 查看按钮的源代码。 ( https://github.com/facebook/react-native/blob/master/Libraries/Components/Button.js )。 他们没有公开任何文本样式的道具。

 const {
      accessibilityLabel,
      color,
      onPress,
      touchSoundDisabled,
      title,
      hasTVPreferredFocus,
      nextFocusDown,
      nextFocusForward,
      nextFocusLeft,
      nextFocusRight,
      nextFocusUp,
      disabled,
      testID,
    } = this.props;

但是,您可以创建一个 TouchableWithNativeFeedback 并添加一个 Text 组件并提供您喜欢的样式。

在字体系列中,您只需输入字体名称

fontfamily:'your-font-family'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM