代码改变世界

react-native中长度单位换算

2020-11-06 15:47  在思考中成长  阅读(300)  评论(0编辑  收藏  举报
import {
   Dimensions,
   Platform
} from 'react-native';


//获取屏幕大小
const { width, height } = Dimensions.get("window");
const ScreenWidth = Math.min( width, 540); //判断是否是 iphone Plus


//db数值转化
export function getPixel(num, designWidth = 375) {
   return num * ScreenWidth / designWidth ;
}