【问题标题】:Camera Roll adding borderColor相机胶卷添加边框颜色
【发布时间】:2019-08-17 11:03:56
【问题描述】:

所以我想创建一个漂亮的相机胶卷 UI,它有一个 borderColor 而不是 marginpadding,因为它会使图像不适合屏幕的宽度。我也不想在图像的右侧和左侧添加borderColor。它只是喜欢在 Instagram 上。

这就是我想要实现的目标:

这是我的代码:

CameraRoll.js

  setIndex = (index) => {
if (index === this.state.index) {
  index = null
}
this.setState({ index });
};

getPhotos = () => {
CameraRoll.getPhotos({
  first: 200,
  assetType: 'All'
})
.then(res => {
  this.setState({ 
    photos: res.edges,
  });
})
.catch((err) => {
  console.log('Error image: ' + err);
});
};

render() {
return(
  <View style={styles.container}>
    <Image 
      source={{uri: this.state.pickedImage}} 
      style={styles.image}
    />
    <ScrollView contentContainerStyle={styles.scrollView} showsVerticalScrollIndicator={false}>
      {this.state.photos.map((photos, index) => {
        return(
          <TouchableHighlight 
            style={{opacity: index === this.state.index ? .5 : 1}}
            onPress={() => this.setState({pickedImage: photos.node.image.uri})}
            key={index}
            underlayColor='transparent'
          >
            <Image
              style={[{width: width / 3, height: width /3}]}
              source={{uri: photos.node.image.uri}}
              resizeMode='cover'
            />
          </TouchableHighlight>
        );
      })}
    </ScrollView>
  </View>
); 
}
}

【问题讨论】:

  • 你可以使用Flatlist
  • @hongdevelop 然后呢?

标签: javascript react-native stylesheet


【解决方案1】:

改变TouchableHighlight或Image的样式,添加borderColor:"red",borderWidth:10

setIndex = (index) => {
if (index === this.state.index) {
  index = null
}
this.setState({ index });
};

getPhotos = () => {
CameraRoll.getPhotos({
  first: 200,
  assetType: 'All'
})
.then(res => {
  this.setState({ 
    photos: res.edges,
  });
})
.catch((err) => {
  console.log('Error image: ' + err);
});
};

render() {
return(
  <View style={styles.container}>
    <Image 
      source={{uri: this.state.pickedImage}} 
      style={styles.image}
    />
    <ScrollView contentContainerStyle={styles.scrollView} showsVerticalScrollIndicator={false}>
      {this.state.photos.map((photos, index) => {
        return(
          <TouchableHighlight 
            style={{
              opacity: index === this.state.index ? .5 : 1,  
              borderColor:"red", borderWidth:10
           }}
            onPress={() => this.setState({pickedImage: photos.node.image.uri})}
            key={index}
            underlayColor='transparent'
          >
            <Image
              style={[{width: width / 3, height: width /3}]}
              source={{uri: photos.node.image.uri}}
              resizeMode='cover'
            />
          </TouchableHighlight>
        );
      })}
    </ScrollView>
  </View>
); 
}
}

【讨论】:

  • 如我所说,我只想在左右两侧添加borderColor。例如,我有 3 列图像,在第一列中,我只想应用 borderRightWidth 而没有 borderLeftWidth ,第二列只有 borderRightWidth 并且也没有 borderLeftWidth 。在最后一列没有borderWidth,所有列都有borderTopWidth
  • 可能你正在使用..borderLeftColor;"red",borderRightColor:"red"
  • 哦,是的,你是对的,但由于borderRightWidth,相机胶卷现在只有 2 行,从 3 行到 2 行。什么是完美合身的完美造型?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-16
  • 2021-04-29
相关资源
最近更新 更多