我有一个UICollectionView
,它有一个标题和一个单元格。
我想删除标题和单元格之间的差距..
如何在swift
?
以下是我的观点......
我为collectionView
和标题和单元格添加了背景颜色..
请参阅截图。
答案 0 :(得分:3)
使用UICollectionViewFlowLayout
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.sectionInset = UIEdgeInsets(top: 0, left: 10, bottom: 10, right: 10)
// Here you can set according your requirement
更多参考:http://www.brianjcoleman.com/tutorial-collection-view-using-swift/
答案 1 :(得分:1)
使用sectionInset
的属性UICollectionViewFlowLayout
:
UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init];
layout.minimumInteritemSpacing = 0;
layout.minimumLineSpacing = 1;
在Swift中:
var layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.minimumInteritemSpacing = 0
layout.minimumLineSpacing = 1
答案 2 :(得分:0)
答案 3 :(得分:0)
我忘了将插入部分设置为零。 它解决了我的问题。 谢谢大家。
答案 4 :(得分:0)
试试这个:
override func viewWillAppear(animated: Bool) {
self.automaticallyAdjustsScrollViewInsets = false;
}
在UICollectionViewDelegate上:
let k_cViewPadding = 8.0
func collectionView(collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
let cellDiffference:CGFloat = CGFloat(k_cViewPadding*4)
return(CGSizeMake((collectionView.frame.size.width-cellDiffference)/3, (collectionView.frame.size.width-cellDiffference)/3))
}
答案 5 :(得分:0)
这是我的示例代码,您必须为间距设置 UIEdgeInsets
。
private let collectionViewLayout: UICollectionView = {
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = UICollectionView.ScrollDirection.horizontal
layout.sectionInset = UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 0)
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
collectionView.translatesAutoresizingMaskIntoConstraints = false
collectionView.showsHorizontalScrollIndicator = false
collectionView.showsVerticalScrollIndicator = false
collectionView.register(CustomCell.self, forCellWithReuseIdentifier: "CollectionViewCell")
collectionView.register(TopExpertCustomCell.self, forCellWithReuseIdentifier: "TopExpertCollectionViewCell")
collectionView.backgroundColor = UIColor(hex: "#F1F1F1")
return collectionView
}()
答案 6 :(得分:0)
自定义您的 UIEdgeInsetsMake:
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
return UIEdgeInsetsMake(0,0,0,0); //{top, left, bottom, right};
}