RN 代码写不同方向的三角形

项目中有时候需要一些三角形图标,UI切图也比较麻烦,这时候仿照CSS样式可以写出同样的效果
先看效果


屏幕快照 2017-09-08 上午10.34.19.png
屏幕快照 2017-09-08 上午10.34.29.png

UI代码如下

 <ScrollView style={styles.container}>

                <View style={styles.triangle_UP}/>
                <View style={styles.triangle_down}/>
                <View style={styles.triangle_left}/>
                <View style={styles.triangle_right}/>
                <View style={styles.triangle_top_right}/>
                <View style={styles.triangle_bottom_left}/>
                <View style={styles.triangle_bottom_right}/>
                <View style={styles.triangle_f}/>
            </ScrollView>

样式代码如下(核心就在样式)

const styles = StyleSheet.create({
    container: {
        flex: 1,

        backgroundColor: '#F5FCFF',
    },

    triangle_UP:{
        width:0,
        height:0,
        borderLeftWidth:50,
        borderLeftColor:'transparent',
        borderRightWidth:50,
        borderRightColor:'transparent',
        borderBottomWidth:100,
        borderBottomColor:'red'
    },
    triangle_down:{
        marginTop: 20,
        width:0,
        height:0,
        borderLeftWidth:50,
        borderLeftColor:'transparent',
        borderRightWidth:50,
        borderRightColor:'transparent',
        borderTopWidth:100,
        borderTopColor:'red'
    },
    triangle_left:{
        marginTop: 20,
        width:0,
        height:0,
        borderTopWidth:50,
        borderTopColor:'transparent',
        borderRightWidth:100,
        borderRightColor:'red',
        borderBottomWidth:50,
        borderBottomColor:'transparent'
    },
    triangle_right:{
        marginTop: 20,
        width:0,
        height:0,
        borderTopWidth:50,
        borderTopColor:'transparent',
        borderLeftWidth:100,
        borderLeftColor:'red',
        borderBottomWidth:50,
        borderBottomColor:'transparent'
    },
    triangle_top_right:{
        marginTop: 20,
        width:0,
        height:0,
        borderLeftWidth:100,
        borderLeftColor:'transparent',
        borderTopWidth:100,
        borderTopColor:'red',
    },
    triangle_bottom_left:{
        marginTop: 20,
        width:0,
        height:0,
        borderRightWidth:100,
        borderRightColor:'transparent',
        borderBottomWidth:100,
        borderBottomColor:'red',
    },
    triangle_bottom_right:{
        marginTop: 20,
        width:0,
        height:0,
        borderLeftWidth:100,
        borderLeftColor:'transparent',
        borderBottomWidth:100,
        borderBottomColor:'red',
    },
    triangle_f:{
        marginTop: 20,
        width:0,
        height:0,
        borderTopWidth:100,
        borderTopColor:'red',
        borderRightWidth:100,
        borderRightColor:'transparent',

    },

});
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,892评论 25 709
  • 我想到了一个不受伤的方式,就是不爱上任何人
    ___海阅读 1,566评论 0 1
  • 很好
    沐窈阅读 1,170评论 0 0
  • 一大早,我迷迷糊糊地咀嚼着老妈买来的早餐,嘴里不忘恨恨地念着:“买来放着不就好了,非要把我叫醒,总是这样!”...
    追风筝的小小郭阅读 1,891评论 0 0
  • 此刻,我躺在长沙发往张家界的火车上铺,感受着由于列车飞速运动产生的剧烈晃动而带来的不适感。 刚才车厢里还有小朋友们...
    流氓兔夫人阅读 1,222评论 0 0