Skip to content

Commit 8545058

Browse files
committed
Added inheritLayoutMarginsForСhilds.
1 parent 8488acb commit 8545058

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

Sources/SparrowKit/UIKit/Classes/SPNavigationController.swift

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,44 @@ open class SPNavigationController: UINavigationController {
6565
*/
6666
open var inheritLayoutMarginsForNavigationBar: Bool = false
6767

68+
/**
69+
SparrowKit: If set to `true`, child controllers apply horizontal margins from view of navigation controller.
70+
Default is `false`.
71+
*/
72+
open var inheritLayoutMarginsForСhilds: Bool = false
73+
6874
open override func viewDidLayoutSubviews() {
6975
super.viewDidLayoutSubviews()
76+
77+
// Inhert of Navigation Bar
78+
7079
if inheritLayoutMarginsForNavigationBar {
71-
navigationBar.layoutMargins.left = view.layoutMargins.left
72-
navigationBar.layoutMargins.right = view.layoutMargins.right
80+
81+
let leftMargin = view.layoutMargins.left
82+
let rightMargin = view.layoutMargins.left
83+
84+
if navigationBar.layoutMargins.left != leftMargin {
85+
navigationBar.layoutMargins.left = leftMargin
86+
}
87+
if navigationBar.layoutMargins.right != rightMargin {
88+
navigationBar.layoutMargins.right = rightMargin
89+
}
90+
}
91+
92+
// Inhert childs controllers
93+
94+
if inheritLayoutMarginsForСhilds {
95+
let leftMargin = view.layoutMargins.left
96+
let rightMargin = view.layoutMargins.left
97+
98+
for childController in viewControllers {
99+
if childController.view.layoutMargins.left != leftMargin {
100+
childController.view.layoutMargins.left = leftMargin
101+
}
102+
if childController.view.layoutMargins.right != rightMargin {
103+
childController.view.layoutMargins.right = rightMargin
104+
}
105+
}
73106
}
74107
}
75108
}

0 commit comments

Comments
 (0)