简体   繁体   English

React Native 字体大小在 Xcode/Simulator 与物理设备上有所不同

[英]React Native font size differs on Xcode/Simulator vs physical device

I have been having trouble getting my React Native app layout to look the same on a physical iPhone 11 Pro as it does on an iOS simulator of an iPhone 11 Pro.我一直无法让我的 React Native 应用程序布局在物理 iPhone 11 Pro 上看起来与在 iPhone 11 Pro 的 iOS 模拟器上看起来一样。 Specifically the issue is with text rendering.具体来说,问题在于文本渲染。 It seems like the font size is simply not the same on the two.两者的字体大小似乎根本不同。

Xcode and Simulator are version 11.7, and iOS 13.7 is on both the phone and the simulator. Xcode 和 Simulator 是 11.7 版本,而 iOS 13.7 是在手机和模拟器上。 React Native is version 0.61.5. React Native 是 0.61.5 版本。

Since I can't share the entire screen I have cropped to the relevant area.由于我无法共享整个屏幕,因此我已裁剪到相关区域。 I have left part of the adjacent graphics in to indicate the dimensions of the space.我留下了相邻图形的一部分以指示空间的尺寸。

iPhone 11 Pro simulator rendering: iPhone 11 Pro 模拟器渲染:

模拟器

iPhone 11 Pro device rendering: iPhone 11 Pro 设备渲染:

iPhone 11 专业版

RN View: RN视图:

    <View style={styles.container}>
      <Image source={require('./assets/tophalf.jpg')}
          style={{width: '100%', height: '50%'}}
          imageStyle={{resizeMode: 'contain'}} />
      <View style={styles.container2}>
      <View style={{flex:1}} />
      <View style={{flex:8}}>
          <View style={{flex:4, alignSelf:'center', width: '85%'}}>
            <Text style={styles.aboutfont}>{loremtext}</Text>
          </View>
          <View style={{flex:2}}>
            <Image source={require('./assets/blob.png')}
                  style={{flex:1, width:'50%', height:'50%', alignSelf: 'flex-end'}}
                  resizeMode="contain" />
          </View>
          <View style={{flex:1}} />
        </View>
      </View>
      <Image source={require('./assets/middlebox.png')}
        style={{position:'absolute', alignItems: 'center',
                width:100, height:100,
                borderWidth:1, borderColor:'#eeeeee', borderRadius:5,
                aspectRatio:1}}
      />
    </View>

And the style elements:和样式元素:

  container: {
    flex: 1,
    backgroundColor: '#ffffff',
    alignItems: 'center',
    justifyContent: 'center',
  },
  container2: {
    flex: 1,
    backgroundColor: 'white',
    justifyContent: 'space-around',
  },
  aboutfont: {
    fontSize: 14,
    fontFamily: Platform.OS === 'ios' ? 'Futura' : 'Roboto',
    color: 'black',
    textAlign: 'center',
  },

Any help would be appreciated.任何帮助,将不胜感激。 I don't know enough to say if this is a React Native issue specifically or something with Xcode/Simulator.我不太清楚这是一个 React Native 问题,还是 Xcode/Simulator 的问题。

my first intuition is that you probably have different settings for text size and/or display zoom on your physical device and your simulator.我的第一个直觉是,您可能对物理设备和模拟器上的文本大小和/或显示缩放有不同的设置。 React Native's Text Component is smart enough to scale with the users' settings, both on iOS and Android. React Native 的文本组件足够智能,可以根据用户的设置进行扩展,无论是在 iOS 还是 Android 上。

Try checking the values in Settings > Display & Brightness > Text Size and in Settings > Display & Brightness > Display Zoom > View尝试检查设置 > 显示和亮度 > 文本大小和设置 > 显示和亮度 > 显示缩放 > 查看中的值

Hope that solves your problem!希望能解决你的问题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM