// // KMNCustomCollectionViewLayout.swift // PDF Reader Pro // // Created by 丁林圭 on 2024/11/9. // import Cocoa class KMNThumCustomCollectionViewFlowLayout: NSCollectionViewFlowLayout { var lineAttributes: NSCollectionViewLayoutAttributes? var lineColor: NSColor = .systemBlue var lineHeight: CGFloat = 4.0 override func layoutAttributesForElements(in rect: NSRect) -> [NSCollectionViewLayoutAttributes] { var attributes = super.layoutAttributesForElements(in: rect) // 将指示线添加到布局属性中 if let lineAttributes = lineAttributes { attributes.append(lineAttributes) } return attributes } func showLine(at indexPath: IndexPath, below rect: NSRect) { let lineAttributes = NSCollectionViewLayoutAttributes(forDecorationViewOfKind: NSUserInterfaceItemIdentifier("Line").rawValue, with: indexPath) lineAttributes.frame = NSRect(x: rect.origin.x, y: rect.origin.y, width: rect.width, height: lineHeight) self.lineAttributes = lineAttributes invalidateLayout() } func hideLine() { lineAttributes = nil invalidateLayout() } }