ios - 在 UICollectionView 中创建的 UIImageView 保持黑色

标签 ios swift uiimageview uicollectionview uicollectionviewcell

我的 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/

相关文章:

ios - 如果我创建个人帐户而不是公司帐户,是否可以让多个开发人员测试我的 iPhone/iPad 应用程序?

ios - 如何解决: Xcode Archive upload failed with error 22421

ios - UITextField 与 UISearchBar?

ios - 如何为不同的屏幕尺寸设置不同的自动布局约束

iphone - 裁剪圆形图像

iphone - UISearchDisplayController 是在模态视图中加载时 TableView 分隔线故障,我该如何解决?

ios - 如何防御IAP Cracker的“耗材”购买?

ios - 无法在属性初始值设定项中使用实例成员 'parseData'

swift - 如何在 Swift 和 SpriteKit 中添加涟漪效果

ios - UIImageView淡出