Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Sources/FSPageViewLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions Sources/FSPagerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down