【问题标题】:putting words in react native shapes将单词放入反应原生形状中
【发布时间】:2021-07-26 08:53:32
【问题描述】:

我正在尝试在我的方格中添加单词,但是当我在框中输入一个长句子时,它会切断很多,有没有人知道如何使它可以开始一个新行而不是继续开箱?我的代码在正方形和文本下方

        <View style={square}>
            <Text
              style={{
                alignItems:'flex-start',
                allowFontScaling: 'True',
                alignContent: 'True',
                color: 'white',
                alignItems: 'True',
                fontSize: 10,
              }}>this is where my long sentence goes to test out my words in the box                </Text>
          </View>
const square = { 
  width: 120,
  height: 80,
  justifyContent: 'center',
  alignItems: 'center',
  backgroundColor: '#6930C3',
  flex:1
};

【问题讨论】:

    标签: react-native text components shapes


    【解决方案1】:

    您可以使用道具numberOfLinesellipsizeMode 来解决您的问题。

    function Example() {
        return (
            <View style={{
                width: 120,
                height: 80,
                justifyContent: 'center',
                alignItems: 'center',
                backgroundColor: '#6930C3',
                margin: 20,
                //padding: 20,
                //flex:1
            }}>
                <Text
                    style={{
                        alignItems: 'flex-start',
                        //allowFontScaling: 'True',
                        //alignContent: 'True',
                        color: 'white',
                        //alignItems: 'True',
                        fontSize: 10,
                    }}
                    // numberOfLines={4}
                    // ellipsizeMode={'clip'}
                    >
                    this is where my long sentence goes to test out my words in the box 4
                    this is where my long sentence goes to test out my words in the box 3 
                    this is where my long sentence goes to test out my words in the box 2
                    this is where my long sentence goes to test out my words in the box 1
                      </Text>
            </View>
        )
    }

    【讨论】:

    • 我尝试了行数道具,但实际上并没有使句子成为我想要的行数。 ellipsizeMode 的值应该是多少?
    • 你能举个例子吗?我把我的代码放在我的答案中,文本默认这样做
    猜你喜欢
    • 2022-01-22
    • 2021-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-23
    • 2020-05-13
    • 1970-01-01
    相关资源
    最近更新 更多