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',

    },

});
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,109評論 25 709
  • 我想到了一個不受傷的方式,就是不愛上任何人
    ___海閱讀 261評論 0 1
  • 很好
    沐窈閱讀 184評論 0 0
  • 一大早,我迷迷糊糊地咀嚼著老媽買來的早餐,嘴里不忘恨恨地念著:“買來放著不就好了,非要把我叫醒,總是這樣!”...
    追風箏的小小郭閱讀 306評論 0 0
  • 此刻,我躺在長沙發(fā)往張家界的火車上鋪,感受著由于列車飛速運動產生的劇烈晃動而帶來的不適感。 剛才車廂里還有小朋友們...
    流氓兔夫人閱讀 195評論 0 0

友情鏈接更多精彩內容