最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Shadow in image React Native - Stack Overflow

programmeradmin4浏览0评论

I'm having difficulty putting a shadow in the image, I tried putting it in View and Image but it did not work

<View style={styles.ContainerImageProfile}>
    <Image style={styles.ImageProfile} source={{uri: 'profile.png'}} />
</View>

ContainerImageProfile: {
        width: 90,
        height: 90,
        borderRadius: 50,
        backgroundColor: 'red',
        overflow: 'hidden',
        marginTop: 100,
        shadowColor: '#000',
        shadowOffset: { width: 0, height: 2 },
        shadowOpacity: 0.8,
        shadowRadius: 50,

    },
    ImageProfile: {
        width: '100%',
        height: '100%'
    },

I'm having difficulty putting a shadow in the image, I tried putting it in View and Image but it did not work

<View style={styles.ContainerImageProfile}>
    <Image style={styles.ImageProfile} source={{uri: 'profile.png'}} />
</View>

ContainerImageProfile: {
        width: 90,
        height: 90,
        borderRadius: 50,
        backgroundColor: 'red',
        overflow: 'hidden',
        marginTop: 100,
        shadowColor: '#000',
        shadowOffset: { width: 0, height: 2 },
        shadowOpacity: 0.8,
        shadowRadius: 50,

    },
    ImageProfile: {
        width: '100%',
        height: '100%'
    },
Share Improve this question asked May 9, 2018 at 22:30 Rafael AugustoRafael Augusto 3974 gold badges13 silver badges29 bronze badges 1
  • are you trying to add shadow inside or outside ? – suchcodemuchwow Commented May 9, 2018 at 23:38
Add a ment  | 

2 Answers 2

Reset to default 4

You need to set the elevation to see the shadow, like you can check in this snack, set backgroundColor in your Component also helps to work both in Android and IOS (i have defined a transparent one)

ContainerImageProfile: {

            width: 90,
            height: 90,
            borderRadius: 50,
            overflow: 'hidden',
            marginTop: 100,

            //Properties to setup your Shadow 

            shadowOffset: { width: 10, height: 10 },
            shadowColor: '#000',
            shadowOpacity: 1,
            elevation: 10,
            backgroundColor : "#000"

        }

Besides elevation (to make it work on Android), your problem here is with the overflow property. Shadows are drawn outside your elements bounds, so it overflows it.

Set overflow to 'visible' and your set.

发布评论

评论列表(0)

  1. 暂无评论