【问题标题】:Use different fonFamilly in the same line of text, in React native在 React native 中,在同一行文本中使用不同的 fonFamily
【发布时间】:2021-11-22 23:52:24
【问题描述】:
我需要在一个句子中申请两个不同的fontFamily。
在短语"String1: second String" 中,我需要"string1:" 是半粗体,而"second String" 是常规。
<Text
style={[
{ color: colors.black, fontFamily: 'Montserrat-SemiBold' },
]}>
String1:
<Text
style={[
{ color: colors.black, fontFamily: 'Montserrat-Regular' },
]}>
second String
</Text>
</Text>
上述代码的结果是把所有的文字都加了半粗体。
【问题讨论】:
标签:
javascript
css
react-native
【解决方案1】:
对于这个问题,我需要在 React-Native 中让一个句子有两个不同的 fontFamily。
为此,我们创建了一个来制作文本行,并在该组件中将句子与不同的 fontFamily 分开。最终结果是图像中的内容,解决方案如下代码。
desired result
解决办法是……
<Text>
<Text
style={[
{ color: colors.black, fontFamily: 'Montserrat-SemiBold' },
]}>
String1:
</Text>
<Text
style={[
{ color: colors.black, fontFamily: 'Montserrat-Regular' },
]}>
second String
</Text>
</Text>
【讨论】:
-
请详细说明您所做的更改以及更改的原因。我建议你阅读How to Answer。我知道这是您自己的问题,但未来的其他读者可能需要了解。