我有一个UICollectionView,它有一个标题和一个单元格。我想删除标题和单元格之间差距。如何在swift中实现?这是我的观点……
UICollectionView
swift
我添加了背景颜色的collectionView和标题和细胞也..请看截图。
collectionView
wqsoz72f1#
使用UICollectionViewFlowLayout的属性section Inset
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/
ryevplcw2#
使用UICollectionViewFlowLayout的属性sectionInset:
sectionInset
UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init]; layout.minimumInteritemSpacing = 0; layout.minimumLineSpacing = 1;
在Swift中:
var layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout() layout.minimumInteritemSpacing = 0 layout.minimumLineSpacing = 1
jjjwad0x3#
附加脚本屏幕的屏幕截图。按照你的故事板设置并检查。希望你的问题能得到解决。
yshpjwxd4#
我忘了将部分插入设置为零。它解决了我的问题。谢谢大家。
9cbw7uwe5#
试试这个:
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)) }
vaj7vani6#
下面是我的示例代码,你必须设置UIEdgeInsets的间距。
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 }()
k4ymrczo7#
自定义UIEdgeInsetsMake:
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { return UIEdgeInsetsMake(0,0,0,0); //{top, left, bottom, right}; }
7条答案
按热度按时间wqsoz72f1#
使用
UICollectionViewFlowLayout
的属性section Inset更多参考:http://www.brianjcoleman.com/tutorial-collection-view-using-swift/
ryevplcw2#
使用
UICollectionViewFlowLayout
的属性sectionInset
:在Swift中:
jjjwad0x3#
附加脚本屏幕的屏幕截图。按照你的故事板设置并检查。希望你的问题能得到解决。
yshpjwxd4#
我忘了将部分插入设置为零。它解决了我的问题。谢谢大家。
9cbw7uwe5#
试试这个:
在UICollectionViewDelegate上:
vaj7vani6#
下面是我的示例代码,你必须设置
UIEdgeInsets
的间距。k4ymrczo7#
自定义UIEdgeInsetsMake: