
[英]Swift UIEdgeInsets not working properly, how to add spacing between cells?
[英]How to set spacing between collectionview cells in Swift?
http://i.stack.imgur.com/8nGKh.png
如何在集合视图单元格中的行之间设置间距。 如您所提供的图片所示,它们距离太近了。
由于它们距离太近,因此标签中的文本不能分成两行,而我试图弄清楚该怎么做,但是找不到任何东西,因为我搜索的所有内容都在目标-c中,而我只是迅速入门。
任何帮助将非常感激! 感谢您的时间!
在实现此布局委托方法后,根据需要更改顶部,左侧,底部和顶部插图:
func collectionView(collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
insetForSectionAtIndex section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: 10.0, left: 10.0, bottom: 10.0, right: 10.0)
}
在您的viewDidLoad中添加以下代码:
if let layout = self.collectionView.collectionViewLayout as? UICollectionViewFlowLayout{
// set the section insets as you required..
layout.sectionInset = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5)
// set the line spacing according to your requirement
layout.minimumLineSpacing = 5
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.