update border color

don't show line for last cell
This commit is contained in:
Pfeil, Scott Robert 2020-10-22 14:14:09 -04:00
parent 256927760f
commit 901b7438ea
3 changed files with 18 additions and 6 deletions

View File

@ -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

View File

@ -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)

View File

@ -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) {