【问题标题】:How to clip off the image if its outside bounds react native如果图像的外部边界反应本机,如何剪掉图像
【发布时间】:2018-12-29 12:12:56
【问题描述】:

我是响应原生开发的新手。我希望图像具有纵横比,当我尝试更改其边界时,边界外的区域应该被剪掉。在 Android 中,它可以正常工作,但在 iOS 中,图像没有剪裁到其边界并显示整个图像。

<View
      style={{
        backgroundColor: "#04894a",
        padding: 10,
        height: 110,
        alignItems: "center"
      }}
    >
 <View
        style={{
          alignItems: "center"
        }}
      >
        <Image
          style={{ height: 150, width: 150 }}
          source={require("../images/wow_logo.png")}
        />
      </View>

图像超出了视图,但仍然完整显示。如果超出范围,我希望将其裁剪。谁能帮我这个?任何链接或建议也表示赞赏。 TIA

【问题讨论】:

  • 在图像或图像父视图中尝试overflow:'hidden'
  • @Coyote 非常感谢!我正在尝试溢出:错误。傻我!
  • 那么它以图像样式或视图样式结束了?
  • @Coyote 在视图样式中

标签: ios image react-native


【解决方案1】:

使用overflow: hidden - 默认情况下,在 react native 中溢出标志是可见的。

同样要保持纵横比,只要给图片一个参数width或height,然后加上style={{ aspectRatio: 3/2 }},这样就可以保持宽高比了。

【讨论】:

  • 我不知道 aspectRatio 属性的存在。我使用它并解决了很多不必要的代码谢谢
猜你喜欢
  • 1970-01-01
  • 2018-10-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多