我的 imageViews 仍然没有显示图像,如果有人能指出哪里出了问题,我们将不胜感激。
这是 Collection View 函数:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell : UICollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("CELL ID", forIndexPath: indexPath) as! UICollectionViewCell
let imageView = UIImageView(frame: cell.contentView.bounds)
imageView.image = UIImage(named: "gear.png")
cell.contentView.addSubview(imageView)
return cell
}
在 viewDidLoad 中我有:
collectionView.delegate = self
collectionView.dataSource = self
collectionView.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: "CELL ID")
用正确的 CELL ID 标识单元格,我知道这部分工作正常,因为我可以设置这些单元格的背景颜色,它会显示出来。 imageView 显示为黑色。我可以在设置 imageView 的同时设置背景颜色,颜色将显示。
最佳答案
确保您有图像命名齿轮并检查扩展。
关于ios - 在 UICollectionView 中创建的 UIImageView 保持黑色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32003758/