首页 > 解决方案 > TextInput中的文本在ios上的位置不正确

问题描述

我有一个textInputin a View,它位于中心,使用flex. 问题是,当您开始在 中书写时textInput,文本会居中,即使我没有那样设置样式...

初始光标位于正确的位置,但一旦用户开始输入,文本就会居中。

奇怪的是,这个问题只发生在ios,而不是android...

我尝试添加样式textAlign: left,但没有任何效果。我做错了什么,我该如何解决?

这是该项目的链接: https ://snack.expo.io/S1PlOqFvN

import React from 'react';
import { StyleSheet, Text, View, TextInput } from 'react-native';

export default class App extends React.Component {
  render() {
    return (
      <View style={styles.container}>
        <TextInput style={styles.textFieldStyling} placeholder="Try typing something..."></TextInput>
        <Text style={styles.textStyling}></Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: 'orange',
    alignItems: 'center',
    justifyContent: 'center',
  },
  textStyling: {
    fontSize: 50,
    textAlign: 'center',
  },
  textFieldStyling: {
      color: 'blue',
  },
});

标签: ioscssreact-native

解决方案


React Native 中的 TextInput 没有关闭标签

  <TextInput
      style={styles.textFieldStyling} 
      placeholder="Try typing something..."
  />

推荐阅读