问题描述
在React Native中使用自定义字体,我想将CSS应用于级联到子元素的Text元素。据我所知,要应用样式,您必须指定具有样式变化的确切字体。例如。 fontFamily: 'Cabin_700Bold'
。但是,我想嵌套组件并保留相同的fontFamily
,但改变其他样式。 This is possible in React Native和Android中,使用自定义字体时在iOS中似乎不起作用。例如:
const InsteadOfThis = (
<Text style={{ fontFamily: 'Cabin_400Regular' }}>
some regular text
<Text style={{ fontFamily: 'Cabin_700Bold' }}>
Bold section
<Text style={{ fontFamily: 'Cabin_500Italic' }}>Italic but not Bold :(</Text>
</Text>
</Text>
)
const IWantThis = (
<Text style={{ fontFamily: 'Cabin' }}>
some regular text
<Text style={{ fontWeight: 'bold' }}>
Bold section
<Text style={{ fontStyle: 'italic' }}>bold and italic!</Text>
</Text>
</Text>
)
使用Google Fonts之类的自定义字体是否可以在iOS上实现?
(用例是从WYSIWYG编辑器输出的,用户可以在其中以任意顺序对文本应用多种样式。例如:<strong><i><u>This is both bold,italic,and underlined</u></i></strong>
。我们提供了一个工具,可以用匹配的React组件替换每个标签,这样<strong>
就变成了<MyStrong>
)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)