ios - React Native Text 组件不会在 View 组件内居中

标签 ios text view center react-native

您好,我认为这应该很简单,但我无法让它工作。似乎无论我做什么,我都无法让文本组件在 View 内水平居中。我试过使用 alignItems:center, justifyContent:center, alignSelf:center, textAlign:center... 没有任何效果。我可以让它垂直居中,但不能水平居中。为什么 yyyy 亲爱的主?

<Animated.View style={[styles.titleContainer]}>
    <Text style={styles.title}>App logo here</Text>
</Animated.View>

如何让文本在垂直和水平方向上都居中?

这是我的 CSS:

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

这是我的结果:

enter image description here

最佳答案

试试这个... 这是一个 working demo

  container: {
    flex: 1,
    marginTop: 30,
    marginBottom: 30,
    justifyContent: 'center',
    backgroundColor: '#fff',
  },
  title: {
    fontSize: 28,
    textAlign: 'center',
  },

关于ios - React Native Text 组件不会在 View 组件内居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33483637/

相关文章:

ios - 加速器 : BlackBerry & iOs?

ios - Xcode 6.3.1 iPhone 模拟器在我的屏幕上显得很大

objective-c - MPMoviePlayerController 控件在 UIModalPresentationFormSheet 样式模式中打开并且用户使视频全屏时

javascript - 文本输入字段中的光标位置

grails - View 中的grails数字( double )格式

html - Docusign 远程电子邮件按钮边框

ios - UItableviewcontroller 不在行中显示数据并创建额外的行

python - 如何在 python 中的匹配行之后获取行

python - 当 x 轴为日期时,如何在 matplotlib 中的 xticks(使用 x 坐标)下方绘制文本?

Android 软键盘推送 View