Files
GitHawk/Classes/Systems/WrappingStaticSpacingFlowLayout.swift
Joe Rocca 17ecfbb518 Added wrapping labels view to RepoSummaryCell (#1245)
* added label list view to repo summary cell

* simpler total label width calculation

* simplified label list view height caching
2017-12-19 14:51:45 -05:00

54 lines
1.6 KiB
Swift
Executable File

//
// WrappingStaticSpacingFlowLayout.swift
// Freetime
//
// Created by Joe Rocca on 12/7/17.
// Copyright © 2017 Ryan Nystrom. All rights reserved.
//
import Foundation
final class WrappingStaticSpacingFlowLayout: UICollectionViewFlowLayout {
var interitemSpacing: CGFloat {
get {
return minimumInteritemSpacing
}
}
var rowSpacing: CGFloat {
get {
return minimumLineSpacing
}
}
init(estimatedItemSize: CGSize = CGSize.zero, interitemSpacing: CGFloat, rowSpacing: CGFloat) {
super.init()
self.estimatedItemSize = estimatedItemSize
self.minimumInteritemSpacing = interitemSpacing
self.minimumLineSpacing = rowSpacing
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
if let attributes = super.layoutAttributesForElements(in: rect) {
for (index, attribute) in attributes.enumerated() {
if index == 0 {
attribute.frame.origin.x = 0
continue
}
let prevLayoutAttributes = attributes[index - 1]
let origin = prevLayoutAttributes.frame.maxX
if (origin + interitemSpacing + attribute.frame.size.width < self.collectionViewContentSize.width) {
attribute.frame.origin.x = origin + interitemSpacing
}
}
return attributes
}
return nil
}
}