
Кто-нибудь знает, что здесь происходит? Вот мой код:
Код: Выделить всё
extension ApodCollectionViewController: UICollectionViewDelegateFlowLayout {
fileprivate enum Constants {
static let numColumns = 3.0
static let spacing = 10.0
}
/// This gives size of each item.
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let availableWidth = collectionView.bounds.width - ((Constants.numColumns+1)*Constants.spacing)
let widthPer = availableWidth/Constants.numColumns
return CGSize(width: widthPer, height: widthPer)
}
/// This gives inset around entire collection view.
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: Constants.spacing, left: Constants.spacing, bottom: Constants.spacing, right: Constants.spacing)
}
/// This gives space between items (horizontal).
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return Constants.spacing
}
/// This gives space between rows (vertical).
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return Constants.spacing
}
}
У кого-нибудь есть идеи? Спасибо!
Подробнее здесь: https://stackoverflow.com/questions/792 ... flowlayout
Мобильная версия