React-Native组件之Text内文字垂直居中方案

Posted hughes5135

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了React-Native组件之Text内文字垂直居中方案相关的知识,希望对你有一定的参考价值。

1 style: {
2   height: 100,
3   textAlign: ‘center‘,
4   textAlignVertical: ‘center‘,  
5 }

以上方法在android上显示水平垂直居中, 但在ios上只能水平居中, 方法是在IOS上添加lineHeight: 100, 如下

1 style: {
2   height: 100,
3   textAlign: ‘center‘,
4   textAlignVertical: ‘center‘,
5   ...Platform.select({
6      ios: { lineHeight: 100},
7      android: {}
8    })
9 }

别忘了在react-native模块中导入组件 StyleSheet和Platform

以上是关于React-Native组件之Text内文字垂直居中方案的主要内容,如果未能解决你的问题,请参考以下文章