Skip to content

Commit 7c3b053

Browse files
committed
Added inhert layout margins to reusable view.
1 parent ca17eb0 commit 7c3b053

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Sources/SparrowKit/UIKit/Classes/Collection/SPCollectionReusableView.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ import UIKit
2929
*/
3030
open class SPCollectionReusableView: UICollectionReusableView {
3131

32+
// MARK: - Private
33+
34+
open var inhertHorizontalMarginsFromCollection: Bool = true
35+
3236
// MARK: - Init
3337

3438
public override init(frame: CGRect) {
@@ -48,5 +52,19 @@ open class SPCollectionReusableView: UICollectionReusableView {
4852
No need ovveride other init. Using one function for configurate view.
4953
*/
5054
open func commonInit() {}
55+
56+
open override func layoutSubviews() {
57+
super.layoutSubviews()
58+
if inhertHorizontalMarginsFromCollection, let collectionView = self.superview as? UICollectionView {
59+
setLayoutMargins(
60+
.init(
61+
top: layoutMargins.top,
62+
left: collectionView.layoutMargins.left,
63+
bottom: layoutMargins.bottom,
64+
right: collectionView.layoutMargins.right
65+
)
66+
)
67+
}
68+
}
5169
}
5270
#endif

0 commit comments

Comments
 (0)