首页 > 解决方案 > 在 TouchableOpacity 上创建“凸起”或阴影效果:React Native

问题描述

我使用react-native-elements,它们可以很容易地使实际按钮显示为“凸起”或阴影。我想复制这个寻找TouchableOpacity

这是一个带有 的“凸起按钮”示例react-native-elements凸起按钮示例

它很微妙,但明显会产生很好的影响。你会如何去模仿这种效果TouchableOpacity呢?

是的,我已经浏览了文档。如果我遗漏了什么,请指出......但我认为没有任何东西可以做到这一点。谢谢。

标签: react-nativebuttonstylingtouchableopacity

解决方案


You can add the following styles to your TouchableOpacity to make it raised.

<TouchableOpacity style={styles.button} />

  button: {
    shadowColor: 'rgba(0,0,0, .4)', // IOS
    shadowOffset: { height: 1, width: 1 }, // IOS
    shadowOpacity: 1, // IOS
    shadowRadius: 1, //IOS
    backgroundColor: '#fff',
    elevation: 2, // Android
    height: 50,
    width: 100,
    justifyContent: 'center',
    alignItems: 'center',
    flexDirection: 'row',
},

You can read more about them here.

IOS Specific Props

Android Specific Props


推荐阅读