У меня есть UICollectionView
, который содержит пользовательские UICollectionViewCell
«с, здесь соответствующий код: UICollectionView пользовательские элементы не отображаются
class customCell: UICollectionViewCell{
var imgView = UIImageView()
override init(frame: CGRect) {
super.init(frame: frame)
commonInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
}
func commonInit(){
imgView.translatesAutoresizingMaskIntoConstraints = false
self.addcontentView.addSubview(imgView)
//add constraints
}
}
class CollectionViewController: UICollectionViewController {
private let imageLib = [...] //image file name strings
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell : IconCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier(keyIconCellReuse , forIndexPath: indexPath) as! IconCollectionViewCell
let image1 = (UIImage(named: imageLib[indexPath.row])?.imageWithRenderingMode(.AlwaysTemplate))!
cell.imgView = UIImageView(image: image1)
cell.imgView.tintColor = UIColor(white:0, alpha:0.7)
cell.userInteractionEnabled = true
return cell
}
}
Это то, что он выглядит сейчас:
Кажется, что вы добавляете новый UIImageView для каждого загруженного изображения. Не могли бы вы использовать метод метода func setUp (imgString: String)? –