Adjust cellsize for fit all screens?

前端 未结 2 1255
长情又很酷
长情又很酷 2020-12-18 17:22

I\'m trying to fit my app to all screensize, however I can\'t figure out how to. Is it possible to resize the cell depending on the screen? At the moment I just configure my

2条回答
  •  情歌与酒
    2020-12-18 18:17

    Drag the collectionViewFlowLayout from the document outline in interface builder into your code to create an outlet. In ViewDidLayoutSubviews (this when you know your frame width) set the width and height:

        //MARK: IBOutlet
        @IBOutlet weak var collectionViewFlowLayout: UICollectionViewFlowLayout!
    
        override func viewDidLayoutSubviews() {
            super.viewDidLayoutSubviews()
            let width = collectionView.frame.size.width - collectionViewFlowLayout.sectionInset.left - collectionViewFlowLayout.sectionInset.right
            collectionViewFlowLayout.itemSize = CGSize(width: width, height: width)
        }
    

提交回复
热议问题