diff --git a/Sources/FSPageViewLayout.swift b/Sources/FSPageViewLayout.swift index 9477ac4..5de2156 100644 --- a/Sources/FSPageViewLayout.swift +++ b/Sources/FSPageViewLayout.swift @@ -75,7 +75,15 @@ class FSPagerViewLayout: UICollectionViewLayout { return pagerView.interitemSpacing }() self.scrollDirection = pagerView.scrollDirection - self.leadingSpacing = self.scrollDirection == .horizontal ? (collectionView.frame.width-self.actualItemSize.width)*0.5 : (collectionView.frame.height-self.actualItemSize.height)*0.5 + + self.leadingSpacing = { + var spacing = pagerView.leadingSpacing + if spacing == .zero { + spacing = self.scrollDirection == .horizontal ? (collectionView.frame.width-self.actualItemSize.width)*0.5 : (collectionView.frame.height-self.actualItemSize.height)*0.5 + } + return spacing + }() + self.itemSpacing = (self.scrollDirection == .horizontal ? self.actualItemSize.width : self.actualItemSize.height) + self.actualInteritemSpacing // Calculate and cache contentSize, rather than calculating each time diff --git a/Sources/FSPagerView.swift b/Sources/FSPagerView.swift index 7fb17d9..d661a74 100644 --- a/Sources/FSPagerView.swift +++ b/Sources/FSPagerView.swift @@ -192,6 +192,14 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega } } + /// The spacing to use leading items in the pager view. Default is 0. + @IBInspectable + open var leadingSpacing: CGFloat = 0 { + didSet { + self.collectionViewLayout.forceInvalidate() + } + } + // MARK: - Public readonly-properties /// Returns whether the user has touched the content to initiate scrolling.