【问题标题】:React-Native: TextInput size is getting increased automatically irrespective of numberOfLines propReact-Native:无论 numberOfLines 属性如何,TextInput 的大小都会自动增加
【发布时间】:2019-12-26 05:33:15
【问题描述】:

我有一个TextInput如下图,

 <TextInput
     style={{borderWidth: 1, borderColor: "#dedede", width: '90%',  marginTop: 20, borderRadius: 1}}
     placeholder={'Tell us more about our service'}
     multiline = {true}
     numberOfLines = {10}
     value={this.state.customerFeedback}
     onChangeText={customerFeedback => this.setState({ customerFeedback })}
     underlineColorAndroid="transparent"
 />

因为我给了numberOfLines = {10},如果我输入超过10行的文字必须在TextInput区域内滚动。但在我的情况下,TextInput 的大小正在逐渐增加,如下图所示,

如果我们查看TextInput,就会发现超过 10 行。

谁能告诉我如何根据numberOfLines 道具限制TextInput 区域?谢谢。

【问题讨论】:

    标签: react-native textinput


    【解决方案1】:

    我看到了您的代码,而您还缺少一个样式属性是 maxHeight。 我将其添加到您的代码中,现在您可以将此代码复制并粘贴到您的项目中。

    {/*maxHeight:200 */}
    <TextInput
     style={{borderWidth: 1, borderColor: "#dedede", width: '90%',  marginTop: 20, borderRadius: 1,maxHeight:200}}
     placeholder={'Tell us more about our service'}
     multiline = {true}
     numberOfLines = {10}
     value={this.state.customerFeedback}
     onChangeText={customerFeedback => this.setState({ customerFeedback })}
     underlineColorAndroid="transparent"
    />
    

    我希望这会有所帮助:)

    【讨论】:

      【解决方案2】:

      您唯一缺少的是 textInput 中样式的 maxHeight 属性,我添加了maxHeight:50:

      <TextInput
           style={{borderWidth: 1, borderColor: "#dedede", width: '90%',  marginTop: 20, borderRadius: 1,maxHeight:50}}
           placeholder={'Tell us more about our service'}
           multiline = {true}
           numberOfLines = {10}
           value={this.state.customerFeedback}
           onChangeText={customerFeedback => this.setState({ customerFeedback })}
           underlineColorAndroid="transparent"
       />
      

      试一试,看看世博小吃expo-snack

      希望对您有所帮助。如有疑问,请随意

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-06-26
        • 1970-01-01
        • 1970-01-01
        • 2014-02-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-02-25
        相关资源
        最近更新 更多