Collection View Cells not appearing

前端 未结 14 836
迷失自我
迷失自我 2021-02-07 08:40

I want to display as many collectionViewCells with buttons as there are strings in my array. but when I start the simulator there is just the backgroun

14条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-07 09:27

    func layoutCells() {
            let layout = UICollectionViewFlowLayout()
            layout.sectionInset = UIEdgeInsets(top: 0, left: 10, bottom: 10, right: 10)
            layout.minimumInteritemSpacing = 5.0
            layout.minimumLineSpacing = 5.0
            layout.itemSize = CGSize(width: (UIScreen.mainScreen().bounds.size.width - 40)/3, height: ((UIScreen.mainScreen().bounds.size.width - 40)/3))
            collectionView!.collectionViewLayout = layout
        }
    

    Try this. Call this function from view did load. I think the problem is that your collection is not laid out correctly.

    func viewDidLoad() {
        layoutCells()
    }
    

    If this works you can modify the layout options to meet your needs.

提交回复
热议问题