简体   繁体   English

在 iOS 中 React Native Rendering Image borderRadius

[英]React Native Rendering Image borderRadius in iOS

Images are rendered in different aspects in ios and android using image component from react-native.图像在 ios 和 android 中使用来自 react-native 的图像组件在不同方面呈现。 I'm trying to display image with 45 degree angle cutoff every corner.我试图在每个角落显示 45 度角截止的图像。

I have tried to use cover, contain and center of the resizeMode prop cover fills the image inside the view giving the 45 degree cut but crops either width or height.我尝试使用 resizeMode 道具的封面、包含和中心覆盖填充视图内的图像,给出 45 度切割,但裁剪宽度或高度。

Center does not crop the image but if the image isn't similar ratio as the view the 45 degree angles aren't cut of the image, Android does this well though. Center 不会裁剪图像,但如果图像与视图的比例不相似,则 45 度角不会切割图像,但 Android 可以很好地做到这一点。

<View style={(this.state.controlsDisplayed) ? styles.flexLR : styles.flexLRBlack}>

  <View style={{flex: (Platform.OS === ‘ios’) ? 0.85 : 0.5}} />

  <View style={styles.imageWrapView}>

    <Image source={{uri: ‘file://’ + item.photoLeft}} key={“TDVIEW”} resizeMode={(Platform.OS == ‘ios’) ? ‘cover’ : ‘center’} style={styles.floatingImagePartView} />

  </View>

  <View style={{flex: (Platform.OS === ‘ios’) ? 0.85 : 0.5}} />

</View>

Want to get uncropped images on ios that have corners cut of by 45 degrees.想要在 ios 上获得切角为 45 度的未裁剪图像。 Same as is in the android images.与 android 图像中的相同。 Here are images from android device that are rendered correctly.以下是来自 android 设备的正确渲染的图像。

android1截止

android1 图像

Here are the images rendered on ios using center and cover以下是使用 center 和 cover 在 ios 上渲染的图像

android1截止

This is rendered using contain on ios这是在 ios 上使用 contains 呈现的

android1截止

android1 图像

How can I get the images rendered with 45 degree cutoff on ios device as it is on an android device?如何在 ios 设备上像在 android 设备上一样获得以 45 度截止呈现的图像?

if you set overflow to hidden the border radius will start working again如果您将溢出设置为隐藏,则边界半径将再次开始工作

 borderRadiusFix:{
        borderRadius: 5,
        overflow: 'hidden',
    }

Try this尝试这个

<View
  style={{
    width: 250,
    height: 150,
    borderTopLeftRadius: 50,
    borderTopRightRadius: 50,
    borderBottomLeftRadius: 50,
    borderBottomRightRadius: 50,
    overflow: 'hidden'
  }}
>
  <Image
    source={{ uri: imageUri }}
    style={{
      width: 250,
      height: 150
    }}
  />
</View>

You can use following props for 45-degree angle cutoff every corner.您可以使用以下道具对每个角落进行 45 度角截断。

borderTopLeftRadius
borderTopRightRadius
borderBottomLeftRadius
borderBottomRightRadius 

same problem are occure with me.同样的问题发生在我身上。 In my case borderRadius are working for android but not working for ios so i followed the folloowing code....就我而言,borderRadius 适用于 android,但不适用于 ios,所以我遵循以下代码....

This is my styling item for Touchable button you can use Image in place...这是我的可触摸按钮的样式项目,您可以就地使用图像...

<View  style = {styles.button}>
                    <TouchableOpacity >
                        <Text style={{textAlign:'center',color:'#ffff'}}>
                        Login
                        </Text>
                    </TouchableOpacity>
                </View>

and my styling....还有我的造型....

 button: {
borderRadius:20,
marginTop:20,
alignSelf:'center',
textAlign:'center',
width:'70%',
height:'7%',
fontWeight:"bold",
color:'#ffff',
paddingTop:10,
backgroundColor: '#00AABF'

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM