Skip to content

Commit 5fffa1d

Browse files
author
Felix Fok
committed
Change: change from WenchaoD#285, making cell align to left
1 parent 1c2aaef commit 5fffa1d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Sources/FSPageViewLayout.swift

+9-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,15 @@ class FSPagerViewLayout: UICollectionViewLayout {
7575
return pagerView.interitemSpacing
7676
}()
7777
self.scrollDirection = pagerView.scrollDirection
78-
self.leadingSpacing = self.scrollDirection == .horizontal ? (collectionView.frame.width-self.actualItemSize.width)*0.5 : (collectionView.frame.height-self.actualItemSize.height)*0.5
78+
79+
self.leadingSpacing = {
80+
var spacing = pagerView.leadingSpacing
81+
if spacing == .zero {
82+
spacing = self.scrollDirection == .horizontal ? (collectionView.frame.width-self.actualItemSize.width)*0.5 : (collectionView.frame.height-self.actualItemSize.height)*0.5
83+
}
84+
return spacing
85+
}()
86+
7987
self.itemSpacing = (self.scrollDirection == .horizontal ? self.actualItemSize.width : self.actualItemSize.height) + self.actualInteritemSpacing
8088

8189
// Calculate and cache contentSize, rather than calculating each time

Sources/FSPagerView.swift

+8
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega
192192
}
193193
}
194194

195+
/// The spacing to use leading items in the pager view. Default is 0.
196+
@IBInspectable
197+
open var leadingSpacing: CGFloat = 0 {
198+
didSet {
199+
self.collectionViewLayout.forceInvalidate()
200+
}
201+
}
202+
195203
// MARK: - Public readonly-properties
196204

197205
/// Returns whether the user has touched the content to initiate scrolling.

0 commit comments

Comments
 (0)