Skip to content

Instantly share code, notes, and snippets.

@YaphetS1
Last active July 15, 2019 16:48
Show Gist options
  • Save YaphetS1/e9af1ec0d69503c4b642c1038bf998db to your computer and use it in GitHub Desktop.
Save YaphetS1/e9af1ec0d69503c4b642c1038bf998db to your computer and use it in GitHub Desktop.
// MARK: - UICollectionViewDelegate
extension MyCollectionAdapter: AdaptiveCollectionLayoutDelegate {
func collectionView(_ collectionView: UICollectionView,
heightForTextAtIndexPath indexPath: IndexPath) -> CGFloat {
if (indexPath.section == 0 && provider.isNeedToShowInfo) {
// In this case I use this for banner in first section where it's occupies the whole area
return AdaptiveCollectionConfig.bannerHeight
} else if let _ = provider.items[indexPath.row] as? Bool {
// In this case I use this for stub elements
return AdaptiveCollectionConfig.placeholderHeight
}
let item = provider.items[indexPath.row] as! MyViewModel
let textHeight = item.title.count
// I get text height and as my font equal ~1pt, it's multiply and than addition it. Maybe you need to
/// modify that value for greater stability height calculations.
/// And you can get there image height for adding it to
let extensionHeight = Double(textHeight) * 0.70
// It's for example, when you need to remove height
//let dateHeight: CGFloat = item.expiring == nil ? -12.5 : 0
return AdaptiveCollectionConfig.cellBaseHeight + CGFloat(textHeight) + CGFloat(extensionHeight)
//+ dateHeight
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment