Big*_*air 6 ios uicollectionview uicollectionviewlayout swift
我使用insetForSectionAtIndex方法为我的集合视图中的一个部分设置contentInset,我不想将该插入应用于该部分的标题.我需要标题宽度与屏幕一样宽.
ConentInset
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets {
if section == 1 {
return UIEdgeInsets(top: 0, left: 15, bottom: 0, right: 15)
}
return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
}
Run Code Online (Sandbox Code Playgroud)
头
override func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
let header = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: opsMainDescriptionSegmentedControlCellId, forIndexPath: indexPath) as! MyHeader
return header
}
Run Code Online (Sandbox Code Playgroud)
我只需要在我的一个项目中做同样的事情.
我申请的解决方案:
在Storyboard中,我的集合视图占据了自动布局约束的全屏.
在viewDidLoad中:
collectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
Run Code Online (Sandbox Code Playgroud)
我将collectionView委托设置为self并且也符合
UICollectionViewDelegateFlowLayout协议.
然后,您可以访问我在返回另一个UIEdgeInsets时使用的方法
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: 15, left: 20, bottom: 15, right: 20)
}
Run Code Online (Sandbox Code Playgroud)
它对我有用.
看看它到底是怎么回事.
希望这能够帮助别人.
你不可以做这个。UICollectionViews标题需要与UICollectionView本身一样宽。如果您希望标头比UICollectionView- 我的建议是在标头内部使用单独的标头UIView并将标头设置为清除。这样看起来它比 的宽度短UICollectionView。
| 归档时间: |
|
| 查看次数: |
4697 次 |
| 最近记录: |