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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM