0
콜렉션 뷰가 있습니다. 셀을 라인 당 4 개의 셀 (특정 스크린 크기)에 맞출 수있는 방법을 찾고있었습니다. 모든 세포의 크기. 나머지 셀에는 재사용 가능한 셀이 있습니다.라인 당 4 개에 맞게 셀의 크기를 자동으로 조정하는 방법
콜렉션 뷰가 있습니다. 셀을 라인 당 4 개의 셀 (특정 스크린 크기)에 맞출 수있는 방법을 찾고있었습니다. 모든 세포의 크기. 나머지 셀에는 재사용 가능한 셀이 있습니다.라인 당 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
}