I’m making an attempt to make slightly horizontal UICollectionView within the prime part of my app however each time I load the app there are all the time like 2 or 3 cells that do not load its content material. And the cells that do not load are altering.
Here’s what I’ve achieved:
public var collectionViewDates = UICollectionView(body: .zero, collectionViewLayout: UICollectionViewFlowLayout())
override func viewDidLoad() {
tremendous.viewDidLoad()
view.addSubview(collectionViewDates)
collectionViewDates.body = CGRect(x: 0,
y: 90,
width: view.width,
peak: 50)
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection part: Int) -> Int {
return 30
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: DatesCollectionViewCell.identifier, for: indexPath) as! DatesCollectionViewCell
cell.dateLabel.textual content = "I dag(indexPath.row)"
return cell
}
func collectionView(_ collectionView: UICollectionView, structure collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: DatesCollectionViewCell.identifier, for: indexPath) as! DatesCollectionViewCell
return CGSizeMake(cell.dateLabel.width + 30, collectionView.peak)
}
And within the cell:
public var dateLabel: UILabel = {
let label = UILabel()
label.textual content = "I dag"
label.adjustsFontSizeToFitWidth = true
label.font = .systemFont(ofSize: 20, weight: .daring)
label.backgroundColor = .systemBlue
return label
}()
override init(body: CGRect) {
tremendous.init(body: body)
addSubview(dateLabel)
dateLabel.body = CGRect(x: 0,
y: 0,
width: 50,
peak: contentView.peak)
dateLabel.middle.y = contentView.middle.y
dateLabel.middle.x = contentView.middle.x
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been applied")
}
I do not perceive why the cells typically load as a result of I’ve achieved this earlier than with different horizontal UICollectionViews. However this time I used to be not so fortunate.