简体   繁体   English

react-native ios 上的垂直中心 TextInput

[英]react-native vertical center TextInput on ios

in react-native when you make a TextInput multiline, the text inside the input is top aligned in IOS and center aligned in Android.在 react-native 中,当您创建 TextInput 多行时,输入内的文本在 IOS 中顶部对齐,在 Android 中居中对齐。
According to the doc we may use 'textAlignVertical' to align top the Text on android But it don't work on IOS根据文档,我们可以使用“textAlignVertical”在 android 上对齐文本,但它不适用于 IOS

my question is: How to vertical align center a Text in IOS multiline TextInput我的问题是:如何在 IOS 多行 TextInput 中垂直对齐文本

Unfortunately the property textAlignVertical is for Android only .不幸的是,属性textAlignVertical仅适用于Android The common workaround is to put the TextInput into the center of a container with a fixed height:常见的解决方法是将TextInput放入具有固定高度的容器的中心:

<View style={{height:200, width:200, justifyContent:"center"}}>
   <TextInput 
     multiline={true} 
     numberOfLines={10} 
     style={{textAlign:"center", width:"100%"}} 
     placeholder="Something useful" />
</View>

or或者

<View style={{height:200, width:200, justifyContent:"center", alignItems:"center"}}>
   <TextInput 
     multiline={true} 
     numberOfLines={10} 
     placeholder="Something useful" />
</View>

will do the trick.会成功的。

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

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