Ios React本机文本组件不会在视图组件内居中

Ios React本机文本组件不会在视图组件内居中,ios,text,view,center,react-native,Ios,Text,View,Center,React Native,嗨,我想这应该很简单,但我不能让它工作。似乎无论我做什么,我都无法使文本组件在视图内水平居中。我尝试过使用alignItems:center、justifyContent:center、alignSelf:center、textAlign:center。。。什么都不管用。我可以让它垂直居中,但不能水平居中。为什么亲爱的主 <Animated.View style={[styles.titleContainer]}> <Text style={styles.title}&

嗨,我想这应该很简单,但我不能让它工作。似乎无论我做什么,我都无法使文本组件在视图内水平居中。我尝试过使用alignItems:center、justifyContent:center、alignSelf:center、textAlign:center。。。什么都不管用。我可以让它垂直居中,但不能水平居中。为什么亲爱的主

<Animated.View style={[styles.titleContainer]}>
    <Text style={styles.title}>App logo here</Text>
</Animated.View>
这是我的结果:

试试这个。。。 这里有一个


添加
flexDirection:'column'
有助于将项目逐列集中对齐:

titleContainer: {
    flex: 1,
    marginTop:30,
    marginBottom:30,
    justifyContent:'center',
},
title:{
    color:'white',
    textAlign:'center',
    alignSelf:'center',
    flexDirection: 'column'
},

对于寻求最简单案例的最低版本的任何人:


我居中
const styles=StyleSheet.create({
containerView:{
为内容辩护:“中心”
}
中心文本:{
自我定位:“中心”
}
})

justifyContent:“中心”
添加到容器视图中。 React native的工作原理与React不同。
因此,对齐不起作用的项目,而不是证明内容起作用。

使用
text对齐:“居中”
属性将文本居中

使用
alignSelf:'center'
属性将视图居中

<View style={{alignSelf:'center'}}>

      <Text style={{textAlign:'center'}}>I'm centered</Text>

</View>

我居中

设置在主视图样式
flex:1
和文本集
textAlign:'center'

titleContainer: {
    flex: 1,
    marginTop:30,
    marginBottom:30,
    justifyContent:'center',
},
title:{
    color:'white',
    textAlign:'center',
    alignSelf:'center',
    flexDirection: 'column'
},
<View style={{alignSelf:'center'}}>

      <Text style={{textAlign:'center'}}>I'm centered</Text>

</View>