ios - 如何在 UICollectionView Swift 中显示多个图像

标签 ios swift

此扩展仅在 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/

相关文章:

ios - JS 代码不在 iOS Web 应用程序模式下执行,但在 iOS Safari 中运行良好

iphone - 如何在 iOS 中使用 jar

ios - 检查 UIViewController 是否正在动画到屏幕上

ios - 我可以从多个线程绘制到同一个 CGContextRef 吗?

swift - 从dae文件中获取预览图,显示在UIImage中

c# - Xamarin.Forms iOS 在设备在线时抛出 NSURLErrorDomain "internet connection offline"

ios - 应用 Uiimageview 的图像比例和 CGaffinetransformation 值不起作用

ios - 看不到标签栏图像

ios - 简单的 getJSON() 函数

Swift http 请求使用 urlSession