ReactNative

React-Native单位转换px转dp

2021-01-10  本文已影响0人  无穷369

计算公式

手机中元素的宽度 = 手机屏幕宽度 * 元素宽度 / 设计稿宽度

工具类 utils.js 代码片段

import { Dimensions } from 'react-native';

// 屏幕宽度
export const screenWidth = Dimensions.get('window').width;

// 屏幕高度
export const screenHeight = Dimensions.get('window').height;

// px转dp
export const pxToDp = (elePx) => screenWidth * elePx / 375;
上一篇下一篇

猜你喜欢

热点阅读