在React Native中仅显示文本的第一行

时间:2018-10-18 01:54:18

标签: reactjs react-native

如何仅显示第一行文字?如果我有这样的东西:

<View> 
  <Text>
    Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, 
  </Text>
</View>

我只想显示“与流行观点相反,Lorem Ipsum”

2 个答案:

答案 0 :(得分:1)

您可以使用道具numberOfLines来限制文本的溢出:

<Text numberOfLines={1}>
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, 
</Text>

这将在达到父视图的限制时自动换行,例如:

 Contrary to popular belief, Lorem Ipsum is not...

答案 1 :(得分:0)

您可以创建一个特殊的Text组件,该组件仅呈现分配值的子字符串。

相关问题