作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用六边形作为背景图标的组件。我正在使用从这个网址复制/粘贴我的代码: https://codedaily.io/tutorials/22/The-Shapes-of-React-Native
我的代码:
六边形.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/
我是一名优秀的程序员,十分优秀!