Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何自动调整单元格大小以适应每行4个单元格_Ios_Swift_Xcode_Swift3_Uicollectionviewcell - Fatal编程技术网

Ios 如何自动调整单元格大小以适应每行4个单元格

Ios 如何自动调整单元格大小以适应每行4个单元格,ios,swift,xcode,swift3,uicollectionviewcell,Ios,Swift,Xcode,Swift3,Uicollectionviewcell,我有一个收集视图,我正在寻找一种方法,找出每行可以容纳4个单元格(在特定屏幕大小上)的单元格大小,并在所有单元格上使用该大小。我有一个可重复使用的电池,我用在其余的电池上 extension LevelSelectController: UICollectionViewDelegateFlowLayout { // Collection view flow layout setup func collectionView(_ collectionView: UICollectionView,

我有一个收集视图,我正在寻找一种方法,找出每行可以容纳4个单元格(在特定屏幕大小上)的单元格大小,并在所有单元格上使用该大小。我有一个可重复使用的电池,我用在其余的电池上

extension LevelSelectController: UICollectionViewDelegateFlowLayout {

// Collection view flow layout setup
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    // Compute the dimension of a cell for an NxN layout with space S between
    // cells.  Take the collection view's width, subtract (N-1)*S points for
    // the spaces between the cells, and then divide by N to find the final
    // dimension for the cell's width and height.

    let cellsAcross: CGFloat = 4
    let spaceBetweenCells: CGFloat = 0
    let dim = (collectionView.bounds.width - (cellsAcross - 1) * spaceBetweenCells) / cellsAcross

    return CGSize(width: dim, height: dim)
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
    return UIEdgeInsetsMake(0, 0, 0.0, 0.0)
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
    return 0.0
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
    return 0.0
}