【问题标题】:Need to make Image Bottom to corner: React Native需要使图像从下到角:React Native
【发布时间】:2018-02-23 12:13:39
【问题描述】:

我想让图像从底部变圆。这是我想做的:

我尝试设置borderRadius,但它会应用于整个图像而不是底部。

这是我的代码:

<View
        style={{
          backgroundColor: ‘transparent’,
          justifyContent: ‘center’,
          alignItems: ‘center’,
          height: 159,
          width: '100%',
          borderBottomWidth: 70,
          borderBottomColor: ‘red’,
          borderBottomRightRadius: 800,
          borderBottomLeftRadius: 800,
        }}
      />

它会给出这样的输出:

我需要设置哪个属性才能在视图底部形成完美的圆形?

【问题讨论】:

  • 半径应用于角而不是边缘
  • @Wainage 没找到你。

标签: android ios image react-native rounded-corners


【解决方案1】:

你可以添加一个透明的png框架,上面有这个形状

你也可以检查一下这可能会有所帮助the-shapes-of-react-native


更新

这是我通过代码管理的方式

首先你创建这个结构

render() {
  return(
    <View style={styles.container} >
      <View style={styles.background} >
        <Image style={styles.image} source={require('./image.jpeg')} />
      </View>
    </View>
  );
}

然后应用这个样式

const styles = {
  container: {
    alignSelf: 'center',
    marginTop: 100,
    width: 200,
    overflow: 'hidden', // for hide the not important parts from circle
    margin: 10,
    height: 100,
  },
  background: { // this shape is a circle 
    borderRadius: 400, // border borderRadius same as width and height
    width: 400,
    height: 400,
    marginLeft: -100, // reposition the circle inside parent view
    position: 'absolute',
    bottom: 0, // show the bottom part of circle
    overflow: 'hidden', // hide not important part of image
  },
  image: {
    height: 100, // same width and height for the container
    width: 200,
    position: 'absolute', // position it in circle
    bottom: 0, // position it in circle
    marginLeft: 100, // center it in main view same value as marginLeft for circle but positive
  }
}

这是结果

【讨论】:

  • 我已经浏览了你的链接。但不知道该怎么做。
  • 如何用这种形状制作一个透明的 png 并使其具有图像上方的绝对位置
  • 我把它留作最后的选择。如果我们得到完美的答案,那么它将在未来有所帮助
【解决方案2】:

使用@Mohamed Khalil提到的方法,

const styles = StyleSheet.create({
containerStyle: {
    alignSelf: 'center',
    width: window.width,
    overflow: 'hidden',
    height: window.width / 1.7
},
sliderContainerStyle: {
    borderRadius: window.width,
    width: window.width * 2,
    height: window.width * 2,
    marginLeft: -(window.width / 2),
    position: 'absolute',
    bottom: 0,
    overflow: 'hidden'
},
slider: {
    height: window.width / 1.7,
    width: window.width,
    position: 'absolute',
    bottom: 0,
    marginLeft: window.width / 2,
    backgroundColor: '#9DD6EB'
}});

这是结果。我在这里使用了Dimensions (const window = Dimensions.get('window');) 以使其对不同的屏幕尺寸更加动态。

【讨论】:

    【解决方案3】:

    如果对你有帮助,你可以查看我的仓库

    https://github.com/paraswatts/React_Native_Custom_shape_image_view/tree/master

    有一个问题,我挤压了图像的宽度,然后在 X 轴上对其进行了缩放

    【讨论】:

      猜你喜欢
      • 2017-06-05
      • 2017-04-03
      • 1970-01-01
      • 1970-01-01
      • 2016-05-25
      • 2022-06-22
      • 2021-03-08
      • 2016-06-22
      • 2020-11-28
      相关资源
      最近更新 更多