本文介绍了如何使用swift 4显示像facebook上传图片这样的collectionView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我想完全按照上图显示 collectionView.我知道它负责 UICollectionViewFlowLayout,但无法做到.非常感谢您的帮助.这是我的代码
Hello i want to show the collectionView exactly as the above image. I know that it responsible for UICollectionViewFlowLayout, but unable to do it. Help is much appreciated. Here is my code
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let yourWidth = (collectionView.bounds.width - 4) / 3.0
let yourHeight = yourWidth
return CGSize(width: yourWidth, height: yourHeight)
}
推荐答案
你的答案在你的问题中,兄弟缺少一些条件
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
switch indexPath.item {
case 0,1:
return CGSize(width: (UIScreen.main.bounds.width - 16) / 2, height: (UIScreen.main.bounds.width - 16) / 2)
default:
return CGSize(width: (UIScreen.main.bounds.width - 32) / 3, height: (UIScreen.main.bounds.width) / 3)
}
}
这篇关于如何使用swift 4显示像facebook上传图片这样的collectionView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!