diff --git a/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift b/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift index 04fc5e70..31222828 100644 --- a/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift +++ b/MVMCoreUI/Atomic/Organisms/Carousel/Carousel.swift @@ -148,9 +148,9 @@ open class Carousel: View { guard let carouselModel = model as? CarouselModel else { return } accessibilityLabel = carouselModel.accessibilityText - collectionView.layer.borderColor = UIColor.black.cgColor + collectionView.layer.borderColor = UIColor.mvmCoolGray3.cgColor collectionView.layer.borderWidth = (carouselModel.border ?? false) ? 1 : 0 - (collectionView.collectionViewLayout as? CarouselCollectionLayout)?.useLines = (carouselModel.border ?? false) + (collectionView.collectionViewLayout as? CarouselCollectionLayout)?.useLines = carouselModel.border ?? false (collectionView.collectionViewLayout as? UICollectionViewFlowLayout)?.minimumLineSpacing = carouselModel.spacing ?? 0 itemWidthPercent = carouselModel.itemWidthPercent / 100.0 diff --git a/MVMCoreUI/Atomic/Organisms/Carousel/CarouselCollectionLayout.swift b/MVMCoreUI/Atomic/Organisms/Carousel/CarouselCollectionLayout.swift index 09841c50..9a7ff06e 100644 --- a/MVMCoreUI/Atomic/Organisms/Carousel/CarouselCollectionLayout.swift +++ b/MVMCoreUI/Atomic/Organisms/Carousel/CarouselCollectionLayout.swift @@ -36,14 +36,26 @@ open class CarouselCollectionLayout: UICollectionViewFlowLayout { return attributes } + func shouldHaveLine(for indexPath: IndexPath) -> Bool { + // No line for the final index + guard let numberOfSections = collectionView?.numberOfSections, + numberOfSections > 0, + let numberOfItemsInLastSection = collectionView?.numberOfItems(inSection: numberOfSections - 1), + numberOfItemsInLastSection > 0, + indexPath.section == numberOfSections - 1, + indexPath.row == numberOfItemsInLastSection - 1 else { return true } + return false + } + open override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { guard let allAttributes = super.layoutAttributesForElements(in: rect) else { return nil } guard useLines else { return allAttributes } - // Add line decorators. var newAttributes = allAttributes allAttributes.forEach { (attributes) in - guard attributes.representedElementCategory == .cell, + + guard shouldHaveLine(for: attributes.indexPath), + attributes.representedElementCategory == .cell, let lineAttributes = layoutAttributesForDecorationView(ofKind: LineDecorationView.elementKind, at: attributes.indexPath), rect.intersects(lineAttributes.frame) else { return } newAttributes.append(lineAttributes) diff --git a/MVMCoreUI/Atomic/Organisms/Carousel/LineDecorationView.swift b/MVMCoreUI/Atomic/Organisms/Carousel/LineDecorationView.swift index 465f2219..5ecd77b1 100644 --- a/MVMCoreUI/Atomic/Organisms/Carousel/LineDecorationView.swift +++ b/MVMCoreUI/Atomic/Organisms/Carousel/LineDecorationView.swift @@ -6,12 +6,12 @@ // Copyright © 2020 Verizon Wireless. All rights reserved. // -public class LineDecorationView : UICollectionReusableView { +public class LineDecorationView: UICollectionReusableView { static public let elementKind = "line" public override init(frame: CGRect) { super.init(frame:frame) - backgroundColor = .black + backgroundColor = .mvmCoolGray3 } public required init?(coder aDecoder: NSCoder) {