gpt4 book ai didi

javascript - 如何在 React Native 中创建六边形 View

转载 作者:行者123 更新时间:2023-12-05 07:26:15 25 4
gpt4 key购买 nike

我想使用六边形作为背景图标的组件。我正在使用从这个网址复制/粘贴我的代码: https://codedaily.io/tutorials/22/The-Shapes-of-React-Native

enter image description here

我的代码:

六边形.js

return (
<View style={styles.hexagon}>
<View style={styles.hexagonInner} />
<View style={styles.hexagonBefore} />
<View style={styles.hexagonAfter} />
</View>
);

const styles = StyleSheet.create({
hexagon: {
width: 100,
height: 55
},
hexagonInner: {
width: 100,
height: 55,
backgroundColor: 'red'
},
hexagonAfter: {
position: 'absolute',
bottom: -25,
left: 0,
width: 0,
height: 0,
borderStyle: 'solid',
borderLeftWidth: 50,
borderLeftColor: 'transparent',
borderRightWidth: 50,
borderRightColor: 'transparent',
borderTopWidth: 25,
borderTopColor: 'red'
},
hexagonBefore: {
position: 'absolute',
top: -25,
left: 0,
width: 0,
height: 0,
borderStyle: 'solid',
borderLeftWidth: 50,
borderLeftColor: 'transparent',
borderRightWidth: 50,
borderRightColor: 'transparent',
borderBottomWidth: 25,
borderBottomColor: 'red'

}
});

然后:

  <View style={{width:100,height:100}}>
<Hexagon />
</View>

但它返回一个红色矩形。

最佳答案

如果您遇到问题,请不要制作其他组件,同样这样做,这将返回您想要的六边形!

像这样使用

            <View style={styles.hexagon}>
<View style={styles.hexagonInner}>
<View style={styles.hexagonBefore}>
</View>
</View>
<View style={styles.hexagonAfter}></View>
</View>

关于javascript - 如何在 React Native 中创建六边形 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54491762/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com