how to set font size for different IOS devices in react native

前端 未结 3 1049
日久生厌
日久生厌 2021-02-02 04:06

In react-native i design a sample,when i check it in different IOS devices here is my code:

render() {
      return (
        

        
3条回答
  •  余生分开走
    2021-02-02 04:30

    Only a concept, but I'd try following:

    const Dimensions = require('Dimensions');
    const Viewport = Dimensions.get('window');
    
    const IPHONE6_WIDTH = 750; // check this, since I'm not sure about iPhone 6 width
    
    class YourComponent extends React.Component {
      constructor(props) {
        super(props);
      }
    
      getFontSize() {
        return ({
          fontSize: ((Viewport.width * Viewport.scale) === IPHONE6_WIDTH) ? 14 : 16
        });
      }
    
      render() {
        
          Continue with Facebook
        
      }
    }
    

提交回复
热议问题