From 33678ccfa3192ad116d104e4f00477374858e081 Mon Sep 17 00:00:00 2001 From: Shezad Ahamed Date: Mon, 23 Jul 2018 15:14:37 +0530 Subject: [PATCH 1/2] Custom section inset added custom initial spacing for cells added --- UPCarouselFlowLayout/UPCarouselFlowLayout.swift | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/UPCarouselFlowLayout/UPCarouselFlowLayout.swift b/UPCarouselFlowLayout/UPCarouselFlowLayout.swift index 3fc3650..f8eefbe 100644 --- a/UPCarouselFlowLayout/UPCarouselFlowLayout.swift +++ b/UPCarouselFlowLayout/UPCarouselFlowLayout.swift @@ -14,6 +14,12 @@ public enum UPCarouselFlowLayoutSpacingMode { case overlap(visibleOffset: CGFloat) } +public enum UPCarouselFlowInitialSpacing { + case startFromZero + case equalSpace + case customSpace(initialX: CGFloat) +} + open class UPCarouselFlowLayout: UICollectionViewFlowLayout { @@ -29,6 +35,7 @@ open class UPCarouselFlowLayout: UICollectionViewFlowLayout { @IBInspectable open var sideItemAlpha: CGFloat = 0.6 @IBInspectable open var sideItemShift: CGFloat = 0.0 open var spacingMode = UPCarouselFlowLayoutSpacingMode.fixed(spacing: 40) + open var initialSpacing = UPCarouselFlowInitialSpacing.equalSpace fileprivate var state = LayoutState(size: CGSize.zero, direction: .horizontal) @@ -60,7 +67,15 @@ open class UPCarouselFlowLayout: UICollectionViewFlowLayout { let yInset = (collectionSize.height - self.itemSize.height) / 2 let xInset = (collectionSize.width - self.itemSize.width) / 2 - self.sectionInset = UIEdgeInsetsMake(yInset, xInset, yInset, xInset) + + switch initialSpacing { + case .startFromZero: + self.sectionInset = UIEdgeInsetsMake(yInset, 0, yInset, xInset) + case .equalSpace: + self.sectionInset = UIEdgeInsetsMake(yInset, xInset, yInset, xInset) + case .customSpace(let initialX): + self.sectionInset = UIEdgeInsetsMake(yInset, initialX, yInset, xInset) + } let side = isHorizontal ? self.itemSize.width : self.itemSize.height let scaledItemOffset = (side - side*self.sideItemScale) / 2 From ba6e4a329d0dba3b3f8e8420a8e9335ab338a7cd Mon Sep 17 00:00:00 2001 From: Shezad Ahamed Date: Fri, 12 Oct 2018 11:38:03 +0530 Subject: [PATCH 2/2] updated to 4.2 --- UPCarouselFlowLayout/UPCarouselFlowLayout.swift | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/UPCarouselFlowLayout/UPCarouselFlowLayout.swift b/UPCarouselFlowLayout/UPCarouselFlowLayout.swift index 456d90b..3e78bd6 100644 --- a/UPCarouselFlowLayout/UPCarouselFlowLayout.swift +++ b/UPCarouselFlowLayout/UPCarouselFlowLayout.swift @@ -68,17 +68,18 @@ open class UPCarouselFlowLayout: UICollectionViewFlowLayout { let xInset = (collectionSize.width - self.itemSize.width) / 2 - switch initialSpacing { + switch initialSpacing { case .startFromZero: - self.sectionInset = UIEdgeInsetsMake(yInset, 0, yInset, xInset) + self.sectionInset = UIEdgeInsets(top: yInset, left: 0, bottom: yInset, right: xInset) case .equalSpace: - self.sectionInset = UIEdgeInsetsMake(yInset, xInset, yInset, xInset) + self.sectionInset = UIEdgeInsets(top: yInset, left: xInset, bottom: yInset, right: xInset) case .customSpace(let initialX): - self.sectionInset = UIEdgeInsetsMake(yInset, initialX, yInset, xInset) + self.sectionInset = UIEdgeInsets(top: yInset, left: initialX, bottom: yInset, right: xInset) } self.sectionInset = UIEdgeInsets.init(top: yInset, left: xInset, bottom: yInset, right: xInset) + let side = isHorizontal ? self.itemSize.width : self.itemSize.height let scaledItemOffset = (side - side*self.sideItemScale) / 2