此扩展仅在 CollectionView 中提供一个 UIImageView。如何显示更多图像,取决于照片数组的大小。照片数组包含图像的 URL 数组(字符串)。
extension FlatViewController: UICollectionViewDataSource{
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return (flat.photos?.count)!
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! CustomCollectionViewCell
cell.imageView.loadImageFromURL(NSURL(string: flat.image!)!)
return cell
}
}
最佳答案
您只需进入 Interface Builder,然后根据需要将一定数量的 ImageView 元素
放入您的 CollectionViewCell
中即可。然后创建 IBOutlets
以引用您在 CollectionViewController
中添加的 ImageView
元素。然后,在函数 cellForItemAtIndexPath
中,只需插入每个 IBOutlet ImageView
的每个图像 URL。
这应该有效。
关于ios - 如何在 UICollectionView Swift 中显示多个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37843244/