zav*_*tra 5 javascript ios reactjs react-native
我有一个View
包含一些组件的反应本机。虽然所有内容在 iPhone 6 和 5 上都能正确显示,但在 iPhone 4s 上查看时,其中一个组件的底部会稍微被切掉。
我看到有一些方法可以缩放 Base64 图标。有什么方法可以将整个容器视图缩放为统一变小或变大吗?
小智 0
这样的事情对你有帮助吗?
YourStyleSheet.js
import {StyleSheet} from 'react-native';
var Dimensions = require('Dimensions');
var {width, height} = Dimensions.get('window');
export function create(styles: Object): {[name: string]: number} {
const platformStyles = {};
Object.keys(styles).forEach((name) => {
let {sm,md,lg, ...style} = {...styles[name]};
// iphone 4s and older
if(sm && width < 375){
style = {...style, ...sm};
}
// iphone 5,5s
if(md && width >= 375 && width <414){
style = {...style, ...md};
}
// iphone 6 and bigger
if(lg && width >= 414){
style = {...style, ...lg};
}
platformStyles[name] = style;
});
return StyleSheet.create(platformStyles);
}
Run Code Online (Sandbox Code Playgroud)
然后,在您的样式中,您可以指定组件在不同屏幕尺寸上的尺寸,如下所示
import YourStyleSheet from './path/YourStyleShett'
const styles = YourStyleSheet.create({
component:{
sm:{fontSize: 20,},
md:{fontSize: 30,},
lg:{fontSize: 30,},
textAlign: 'center',
marginBottom: 10,
fontWeight:'bold',
color:colors.white,
}
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8541 次 |
最近记录: |