简体   繁体   English

TextInput对齐方式未居中iOS React-Native

[英]TextInput Alignment Not Centered iOS React-Native

Why does iOS not center the text input control? 为什么iOS不能使文本输入控件居中? I am including the render and stylesheet code: 我包括了渲染和样式表代码:

left android, right ios 左android,右ios

render() {
  return (

  <View style={styles.container}>
    <TextInput
           style={styles.input}
           onChangeText={(text) => this.setState({text})}
           underlineColorAndroid='rgba(0,0,0,0)'
           value={this.state.text}
           placeholder= 'username'
           />
  </View>
)
}


  const styles = StyleSheet.create({
  container: {
  flex: 1,
  justifyContent: 'center',
  alignItems: 'center',
  backgroundColor: '#13493A'
}

 input: {
   height: 40,
   width: 250,
   borderRadius: 5,
   backgroundColor: '#598176',
   color: 'white',
   marginTop: 30,
   textAlign: 'center'
  }
});

Thank you in advance, Anthonie 提前谢谢你,安东尼奥

Looking on the issue tracker, this appears to be a bug in React Native on iOS: #11892 So your code should work but doesn't. 查看问题跟踪器,这似乎是iOS上的React Native中的一个错误: #11892因此,您的代码应该可以工作,但不能。 There is a listed workaround which is to add alignSelf: 'center' to the TextInput's styles ( see example ). 列出了一种解决方法,该方法是将alignSelf: 'center'添加到TextInput的样式中( 请参阅示例 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM