[英]How to use different styles for android and ios on react-native?
我想为 ios 和 android 使用不同的样式,我该怎么做? 也许有人知道如何风格化 TextInput,我只需要底部边框,但 borderBottomWidth 不起作用。
有很多方法可以实现这一目标。 在您的情况下,最简单的方法是使用 Platform.OS:
var {Platform} = React; var styles = StyleSheet.create({ height: (Platform.OS === 'ios') ? 200 : 100 });
从https://facebook.github.io/react-native/docs/platform-specific-code ,您可以使用Platform.select
还有一个 Platform.select 方法可用,给定一个包含 Platform.OS 作为键的对象,返回您当前运行的平台的值。
import { Platform, StyleSheet } from 'react-native'
const styles = StyleSheet.create({
container: {
flex: 1,
...Platform.select({
ios: {
backgroundColor: 'red',
},
android: {
backgroundColor: 'blue',
},
}),
}
})
import { Platform, StyleSheet } from 'react-native'
const styles = StyleSheet.create({
logo: {
width: (Platform.OS === 'ios') ? 80 : 100,
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.