@@ -63,38 +63,44 @@ public class SeparatorCollectionViewFlowLayout: UICollectionViewLeftAlignedLayou
6363 atIndexPath indexPath: NSIndexPath ) -> UICollectionViewLayoutAttributes ? {
6464 super. layoutAttributesForDecorationViewOfKind ( elementKind, atIndexPath: indexPath)
6565
66- guard let cellAttributes = layoutAttributesForItemAtIndexPath ( indexPath) else {
67- return nil
66+ var frame = CGRect . zero
67+
68+ if let rows = collectionView? . numberOfItemsInSection ( 0 ) where indexPath. row < rows {
69+ if let cellAttributes = layoutAttributesForItemAtIndexPath ( indexPath) {
70+ frame = cellAttributes. frame
71+ }
6872 }
6973
7074 let layoutAttributes = ColoredViewLayoutAttributes ( forDecorationViewOfKind: elementKind,
7175 withIndexPath: indexPath)
7276
73- let baseFrame = cellAttributes. frame
74-
7577 switch elementKind {
7678 case SeparatorCollectionViewFlowLayout . rightSeparatorKind:
77- layoutAttributes. frame = CGRect ( x: baseFrame . maxX,
78- y: baseFrame . minY - separatorWidth, width: separatorWidth,
79- height: baseFrame . height + separatorWidth * 2 )
79+ layoutAttributes. frame = CGRect ( x: frame . maxX,
80+ y: frame . minY - separatorWidth, width: separatorWidth,
81+ height: frame . height + separatorWidth * 2 )
8082 case SeparatorCollectionViewFlowLayout . leftSeparatorKind:
81- layoutAttributes. frame = CGRect ( x: baseFrame . minX - separatorWidth,
82- y: baseFrame . minY - separatorWidth, width: separatorWidth,
83- height: baseFrame . height + separatorWidth * 2 )
83+ layoutAttributes. frame = CGRect ( x: frame . minX - separatorWidth,
84+ y: frame . minY - separatorWidth, width: separatorWidth,
85+ height: frame . height + separatorWidth * 2 )
8486 case SeparatorCollectionViewFlowLayout . topSeparatorKind:
85- layoutAttributes. frame = CGRect ( x: baseFrame . minX,
86- y: baseFrame . minY - separatorWidth, width: baseFrame . width,
87+ layoutAttributes. frame = CGRect ( x: frame . minX,
88+ y: frame . minY - separatorWidth, width: frame . width,
8789 height: separatorWidth)
8890 case SeparatorCollectionViewFlowLayout . bottomSeparatorKind:
89- layoutAttributes. frame = CGRect ( x: baseFrame . minX,
90- y: baseFrame . maxY, width: baseFrame . width,
91+ layoutAttributes. frame = CGRect ( x: frame . minX,
92+ y: frame . maxY, width: frame . width,
9193 height: separatorWidth)
9294 default :
9395 break
9496 }
9597
9698 layoutAttributes. zIndex = - 1
97- layoutAttributes. color = separatorColor
99+ if let rows = collectionView? . numberOfItemsInSection ( 0 ) where indexPath. row >= rows {
100+ layoutAttributes. color = UIColor . clearColor ( )
101+ } else {
102+ layoutAttributes. color = separatorColor
103+ }
98104
99105 return layoutAttributes
100106 }
0 commit comments