• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
骑着小毛驴过冬的八阿哥
博客园    首页    新随笔    联系   管理    订阅  订阅

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

posted @ 2018-11-20 16:44  浅草马甲  阅读(8644)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3