ios - 如何使 UICollectionViewCell 高度填充框架的所有大小?
<p><p>我正在尝试使用 CollectionViewCell 来填充 CollectionView 的所有框架,但是我无法做到这一点,相反,它看起来像这样:
<a href="http://i.stack.imgur.com/ef5pg.png" rel="noreferrer noopener nofollow">How it currently looks</a> </p>
<p>如您所见,uicollectionview 框架的顶部和底部有一个空间,不应该出现。</p>
<p>配置如下:</p>
<pre><code>//////////////////////////////
// Collection View //
//////////////////////////////
self.collectionView.delegate = self
self.collectionView.dataSource = self
self.automaticallyAdjustsScrollViewInsets = false
let screenWidth = UIScreen.mainScreen().bounds.width
let viewHeight = viewContainer.frame.height
let collectionViewFlowLayout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout
collectionViewFlowLayout.itemSize = CGSizeMake(screenWidth, viewHeight)
collectionViewFlowLayout.minimumInteritemSpacing = 0.0
collectionViewFlowLayout.minimumLineSpacing = 0.0
collectionViewFlowLayout.sectionInset = UIEdgeInsetsMake(0.0, 0.0, 0.0, 0.0)
</code></pre>
<p>如何删除这些不需要的空格?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>重写 UICollectionViewFlowLayout 委托(delegate)方法并返回大小等于 collectionview 大小:</p>
<pre><code>func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
return collectionView.frame.size;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何使 UICollectionViewCell 高度填充框架的所有大小?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/34184795/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/34184795/
</a>
</p>
页:
[1]