Swift 4.2
I came here because of the same issue but for Swift and I fixed it using this, I hope it helps:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath)
let title = UILabel(frame: CGRect(x: 0, y: 0, width: cell.bounds.size.width, height: 50))
title.text = "Some random text"
title.font = UIFont(name: "AvenirNext-Bold", size: 15)
title.textAlignment = .center
cell.contentView.addSubview(title)
return cell
}
Do not forget to register the cell:
collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "cellId")