我有一个加载动态内容的集合视图。当我试图加载其中一个单元格时,我设置的高度和宽度不同。 图像视图的内容模式是AspectFit,绘图设置为剪切到边界。
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "included", for: indexPath) as! IncludeCollectionViewCell
let imagename = fabric[indexPath.row].fabricImage
let url = NSURL(string: "http://www.junaidkk.com/images/fabric/thumb/"+imagename!)!
print(url)
cell.fabricImage.sd_setImage(with: url as URL!, placeholderImage: UIImage(named: "default_logo"), options: .transformAnimatedImage, progress: nil, completed: nil)
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: CGFloat((collectionView.frame.size.width / 2) - 5), height: CGFloat(160))
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return 10
}