我正在使用UICollectionView,它有自定义UICollectionViewLayout.I需要在UICollectionViewCell周围的空间,就像我可以得到,如果我使用UICollectionViewFlowLayout与此minimumInteritemSpacingForSectionAtIndex和minimumLineSpacingForSectionAtIndex。
此属性不在UICollectionViewLayout中。那么我如何在swift 2.1或任何想法中管理UICollectionViewCell之间的间距?
我试过这个
let bcolor : UIColor = UIColor.whiteColor()
dataCell.layer.borderColor = bcolor.CGColor
dataCell.layer.borderWidth = 0.9
dataCell.layer.cornerRadius = 3
有什么好主意吗?
答案 0 :(得分:0)
经过一番愚蠢的研究后,我认为这段代码为您提供了所需的骨架:
import UIKit
class UICVC: UICollectionViewController, UICollectionViewDelegateFlowLayout {
// You probably want to implement this
func collectionView(collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
return CGSize(width: 100, height: 100)
}
func collectionView(collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat {
return CGFloat(10)
}
func collectionView(collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat {
return CGFloat(10)
}
}
let uicv = UICollectionView()
uicv.delegate = UICVC()
此代码可确保Collection View的单元格大小合适。假设您的集合视图是标准网格,这应该适用于调整单元格大小。当然,在细胞内定位内容是另一回事。