【问题标题】:How do I set the initial position of the textinput cursor to the top-left corner [duplicate]如何将textinput光标的初始位置设置为左上角[重复]
【发布时间】:2019-11-22 02:49:49
【问题描述】:

我得到了一个 TextInput,由于某种原因,它的初始起点位于中间,如图所示:

我怀疑 textinput 认为第一行从那里开始,但我想知道如何告诉它否则

我希望它从左上角开始。

这就是代码的样子:

<View style={styles.desc}>
     <Text style={styles.text}>Beskrivelse:</Text>
     <TextInput style={styles.desctextinput}
                multiline={true}
                onChangeText={(newText) => {
                     let obj = this.state.data;
                     obj.description = newText;
                     this.setState({data: obj});
                }}
                onBlur={() => {
                     console.log(this.state.data.description)
                }}
                />
</View>
const styles = StyleSheet.create({
    text: {
        fontSize: 16,
        fontWeight: 'bold'
    },
    desc: {
        flexDirection: 'column',
        paddingVertical: 10,
        paddingHorizontal: 15,
        height: 300
    },
    desctextinput: {
        flex: 1,
        borderWidth: 1,
        paddingTop: 5,
        paddingLeft: 5,
        borderColor: '#f7f7f7'
    }

});

【问题讨论】:

  • 也许 flex 1 正在增长它而不改变起始位置。尝试将 flex 更改为一个高度,看看它是否有效。

标签: javascript react-native textinput


【解决方案1】:

您可以通过添加以下内容轻松解决此问题:

textAlignVertical: 'top'

到您的 desctextinput 样式。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-14
    • 2014-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多