TextInput对齐未居中的iOS React-Native

时间:2017-04-05 15:25:02

标签: react-native

为什么iOS不以文本输入控件为中心? 我包括渲染和样式表 代码:

left android, right 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'
  }
});

提前谢谢你, 的安东尼奥

1 个答案:

答案 0 :(得分:2)

查看问题跟踪器,这似乎是iOS上React Native的一个错误:#11892因此,您的代码应该可以正常工作但不会。列出的解决方法是将alignSelf: 'center'添加到TextInput的样式(see example)。