Adjust cellsize for fit all screens?

前端 未结 2 1259
长情又很酷
长情又很酷 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:03

    Try this Code:

    Implement the following functions from collectionView's protocol:

      // cell size
     func collectionView(collectionView: UICollectionView,
        layout collectionViewLayout: UICollectionViewLayout,
        sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
    
      // To get 1 column
     return CGSize(width: view.frame.size.width, height: view.frame.size.width)
    
     // To get 2 column
     //return CGSize(width: view.frame.size.width/2, height: view.frame.size.width/2)
    
     // To get 3 column
     // return CGSize(width: view.frame.size.width/3, height: view.frame.size.width/3)
    
     // Toget 4 column
     // return CGSize(width: view.frame.size.width/4, height: view.frame.size.width/4)
      }
    

    ...where view is your controller's (super) view

     // inter-spacing
    
    func collectionView(collectionView: UICollectionView,
        layout collectionViewLayout: UICollectionViewLayout,
        minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat {
    return 2.0
    }
    
    // line-spacing
    
    func collectionView(collectionView: UICollectionView, layout
        collectionViewLayout: UICollectionViewLayout,
        minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat {
    return 2.0
    }
    

    CollectionView layout principle.

提交回复
热议问题