我想在 react-native 项目中画一个圆环。我希望圆环组件在使用时可以自定义其大小。这是我尝试过的:
import React from 'react';
import {View, StyleSheet, TouchableOpacity} from 'react-native';
const Ring = ({size}) => {
return (
<View
style={[styles.circle, {width: size, height: size}]}
/>
);
};
const styles = StyleSheet.create({
circle: {
width: 100,
height: 100,
borderRadius: 50,
borderWidth: 15,
borderColor: 'blue',
},
});
export default Ring;
当我使用我的Ring
组件时,如下所示:
const MyScreen = () => {
return (
<TouchableOpacity>
<View style={styles.container}>
<Ring size={6} />
<Text>XYZ</Text>
</View>
</TouchableOpacity>
);
};
const styles = StyleSheet.create({
container: {
flexDirection: 'row',
paddingVertical: 17,
paddingHorizontal: 36,
},
});
export default MyScreen;
然而,它显示了一个实心圆圈而不是环形。我怎样才能有一个圆环?