Пример из моего проекта. (
Код не привожу текстом, ужасный редактор.)
В делегате:
![5c7bf8b3c0d26725364424.png](https://habrastorage.org/webt/5c/7b/f8/5c7bf8b3c0d26725364424.png)
internal override func collectionView(
_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath
) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCell(
withReuseIdentifier: CategoriesCollectionViewCell.reuseIdentifier,
for: indexPath
) as! CategoriesCollectionViewCell
let randomIndex = indexPath.item % CategoriesPlaceholder.images.count
cell.configure(
withImage: UIImage(named: CategoriesPlaceholder.images[randomIndex])!,
andTitle: CategoriesPlaceholder.titles[randomIndex]
)
return cell
}
Внутри ячейки:
![5c7bf8c1617ce913362365.png](https://habrastorage.org/webt/5c/7b/f8/5c7bf8c1617ce913362365.png)
internal final class CategoriesCollectionViewCell: UICollectionViewCell {
// =====================================
// MARK: - Configure
// =====================================
internal func configure(withImage image: UIImage?, andTitle title: String) {
illustrationCircle.image = image
self.title.text = title
}