【问题标题】:React Native - Image Semi Circle (using CSS)React Native - 图像半圆(使用 CSS)
【发布时间】:2018-05-03 07:17:32
【问题描述】:

我有一个圆形图像,我需要使用 React Native 将其显示在 Semi Circle 中,如 在附件中显示。请帮忙处理 CSS。

【问题讨论】:

    标签: css image react-native geometry


    【解决方案1】:

    这是我为图像的左右位置找到的解决方案:

    renderLeftRightImage (item, index) {
        var imagePath = item.image?(Strings.BASE_IMAGE_URL+item.image[0].image):'https://placeimg.com/640/480/people';        
    
        if(item.position == 'left'){
            return(
                <View style={{overflow: 'hidden', width : 105, height:210, position : 'absolute', left:80,  bottom:62, borderTopLeftRadius:150, borderBottomLeftRadius:150, backgroundColor:'transparent'}}>
                    <Image style={{width : 210, height:210}} source={{uri:imagePath}}/>
                </View>
            )
        }
        else if(item.position == 'right'){
            return(
                <View style={{overflow: 'hidden', width : 105, height:210, position : 'absolute', right:80,  bottom:62, borderTopRightRadius:150, borderBottomRightRadius:150, backgroundColor:'transparent'}}>
                    <Image style={{width : 210, height:210, position:'absolute', right:0}} source={{uri:imagePath}}/>
                </View>
            )
        }
        else{
            return null;
        }
    }
    

    【讨论】:

      【解决方案2】:

      您可以将overflow CSS prop 与border-radius 组合使用

      示例

      export default class App extends Component {
        render() {
          return (
            <View style={styles.container}>
              <View style={styles.imageContainer}>
                <View style={styles.imageWrapper}>
                  <Image source={{uri: 'https://dummyimage.com/500x500/000/fff.png'}} style={styles.image} />
                </View>
              </View>
            </View>
          );
        }
      }
      
      const styles = StyleSheet.create({
        container: {
          flex: 1,
        },
        imageContainer: {
          alignItems: 'center',
          backgroundColor: 'yellow'
        },
        imageWrapper: {
          width: 125, // half of the image width
          height: 250,
          backgroundColor: 'transparent',
          overflow: 'hidden'
        },
        image: {
          width: 250,
          height: 250,
          borderRadius: 125, // half of the image width
          backgroundColor: 'transparent'
        }
      });
      

      【讨论】:

      • 感谢@bennygenel,但我已经做了一些尝试和错误并得到了这个:&lt;View style={{overflow: 'hidden', width : 105, height:210, position : 'absolute', left:80, bottom:62, borderTopLeftRadius:150, borderBottomLeftRadius:150, backgroundColor:'transparent'}}&gt; &lt;Image style={{width : 210, height:210}} source={{uri:imagePath}}/&gt; &lt;/View&gt;
      • @Amit 'overflow' 属性有帮助。谢谢。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多