如何在反应原生中将<Text>文本设置为大写

Thi*_*vya 61 react-native

如何<Text> some text </Text>在反应原生中设置为大写

<Text style={{}}> Test </Text>
Run Code Online (Sandbox Code Playgroud)

需要证明Test as TEST.

Thi*_*vya 101

@Cherniv谢谢你的回答

<Text style={{}}> {'Test'.toUpperCase()} </Text>
Run Code Online (Sandbox Code Playgroud)

  • @Michal文本动画到大写的样子是什么样的,听起来像是一个超酷的效果,我现在无法想象它. (13认同)
  • 这不是一个真正的解决方案.如果我想将文本设置为大写,该怎么办? (6认同)
  • @Michal使用[Lottie](https://github.com/airbnb/lottie-react-native)可以制作很酷的动画,即使是文本也可以。您可以通过Adobe After Effects创建自定义动画,[示例](https://raw.githubusercontent.com/airbnb/lottie-react-native/master/docs/gifs/Example4.gif)。 (2认同)
  • 这不再是正确的答案。React Native中有默认样式用于文本转换。请在下面检查我的答案。 (2认同)

Bla*_*ack 71

iOS textTransform支持已添加到0.56版本的react-native中.它接受以下选项之一:

  • 没有
  • 大写
  • 小写
  • 利用

实际的提交文档

例:

<View>
  <Text style={{ textTransform: 'uppercase'}}>
    This text should be uppercased.
  </Text>
  <Text style={{ textTransform: 'capitalize'}}>
    Mixed:{' '}
    <Text style={{ textTransform: 'lowercase'}}>
      lowercase{' '}
    </Text>
  </Text>
</View>
Run Code Online (Sandbox Code Playgroud)

更新: 支持已添加到0.57.4的Android中,但有一个错误,请参阅GitHub问题


小智 14

在样式标签中使用文本转换属性

textTransform:'uppercase'
Run Code Online (Sandbox Code Playgroud)


Naj*_*thi 5

React Native .toUpperCase() 函数在字符串中工作正常,但如果您使用numbersor other non-string data types,它不起作用。该error会时有发生。

下面两个是字符串属性:

<Text>{props.complexity.toUpperCase()}</Text>

<Text>{props.affordability.toUpperCase()}</Text>
Run Code Online (Sandbox Code Playgroud)