React Native for iOS 中宽度、高度、填充等的默认单位是什么? [英] What is the default unit for width, height, padding etc in React Native for iOS?

查看:79
本文介绍了React Native for iOS 中宽度、高度、填充等的默认单位是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 iOS 构建 React Native 应用程序.facebook 文档说宽度、高度、填充、边距等需要一个数字.

I am building a React Native application for iOS. The facebook documentation says width, height, padding, margin etc. takes a number.

我想知道样式的默认单位是什么.

I wanted to know what the default unit of styling is.

<View style={styles.box}>
   <Text style={styles.text}> Test Component </Text>
</View>

var styles = ReactNative.StyleSheet.create({
       box: {
          padding: 10,
          width:100,
          height:100,
       },
       text: {
          color: 'black',
          fontSize: 30,
       },
});

推荐答案

来自 文档:

React Native 中的所有维度都是无单位的,代表与密度无关的像素.以这种方式设置尺寸对于应该始终以完全相同的尺寸呈现的组件来说很常见,而不管屏幕尺寸如何.

All dimensions in React Native are unitless, and represent density-independent pixels. Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

所以单位尺寸是dp.

这篇关于React Native for iOS 中宽度、高度、填充等的默认单位是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆