Hello,
I have been exploring UICollecitonView and UICollectionViewLayout. For my purposes UICollectionViewFlowLayout its enough. But I want to have that for some items at some index paths the line space between the items will be the minimun, and for the rest, some other value (to a max of 3 points)
I have subclassed UICollectionViewFlowLayout and override these methods:
override func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes!{
var attributes:UICollectionViewLayoutAttributes = super.layoutAttributesForItemAtIndexPath(indexPath)
self.modifyLayoutAttributes(&attributes)
return attributes
}
override func layoutAttributesForElementsInRect(rect: CGRect) -> [AnyObject]? {
let attributesInRect:[UICollectionViewLayoutAttributes] = super.layoutAttributesForElementsInRect(rect) as! [UICollectionViewLayoutAttributes]
for var index = 0; index < count(attributesInRect); ++index {
var cellAttributes = attributesInRect[index]
self.modifyLayoutAttributes(&cellAttributes)
}
return attributesInRect
}
func modifyLayoutAttributes(inout attributes:UICollectionViewLayoutAttributes){
let indexPath = attributes.indexPath
if let edgeInsets = self.attributesDelegate?.edgeInsetsForRowAt(indexPath) {
var frame:CGRect = attributes.frame
frame = UIEdgeInsetsInsetRect(frame, edgeInsets)
attributes.frame = frame
}
}
The first time the collection view loads the spacing seems fine, but once I start scrolling all the spacings goes to the minimun spacing....
What I want to achieve is to kinda group cells together based om soome logic so the user will see this cells closer together.
Now something I can't do is to separate into diferent sections, the sectioning logic is working, I have sections by day, but the cells are kinda topics, which when related are under each other I want to have them be closer together as to "visualize" some group made of cells.
Is this even possible?
Thanks
Gustavo.
PS: Im sorry if this was asked before, if so , please any help to give me some lights in the right direction wil lbe much appreciated. 🙂