React Native Responsive Font Size

前端 未结 14 1274
执念已碎
执念已碎 2020-11-29 16:39

I would like to ask how react native handle or do the responsive font. For example in iphone 4s i Have fontSize: 14, while in iphone 6 I have fontSize: 18.

14条回答
  •  心在旅途
    2020-11-29 17:17

    I recently ran into this problem and ended up using react-native-extended-stylesheet

    You can set you rem value and additional size conditions based on screen size. As per the docs:

    // component
    const styles = EStyleSheet.create({
      text: {
        fontSize: '1.5rem',
        marginHorizontal: '2rem'
      }
    });
    // app entry
    let {height, width} = Dimensions.get('window');
    EStyleSheet.build({
      $rem: width > 340 ? 18 : 16
    });
    

提交回复
热议问题