@@ -7,6 +7,12 @@ import UIKit
77
88@objc ( HYPPagesController) public class PagesController : UIPageViewController , UIPageViewControllerDelegate , UIPageViewControllerDataSource {
99
10+ struct Dimensions {
11+ static let bottomLineHeight : CGFloat = 1.0
12+ static let bottomLineSideMargin : CGFloat = 40.0
13+ static let bottomLineBottomMargin : CGFloat = 36.0
14+ }
15+
1016 public var startPage = 0
1117 public var setNavigationTitle = true
1218
@@ -16,12 +22,27 @@ import UIKit
1622 }
1723 }
1824
25+ public var showBottomLine = false {
26+ didSet {
27+ bottomLineView. hidden = !showBottomLine
28+ }
29+ }
30+
1931 lazy var pages = Array < UIViewController > ( )
2032
2133 public private( set) var currentIndex = 0
2234
2335 public var pagesDelegate : PagesControllerDelegate ?
2436
37+ public private( set) var bottomLineView : UIView = {
38+ let view = UIView ( )
39+ view. setTranslatesAutoresizingMaskIntoConstraints ( false )
40+ view. backgroundColor = . whiteColor( )
41+ view. alpha = 0.4
42+ view. hidden = true
43+ return view
44+ } ( )
45+
2546 public convenience init ( _ pages: [ UIViewController ] ,
2647 transitionStyle: UIPageViewControllerTransitionStyle = . Scroll,
2748 navigationOrientation: UIPageViewControllerNavigationOrientation = . Horizontal,
@@ -38,6 +59,10 @@ import UIKit
3859
3960 delegate = self
4061 dataSource = self
62+
63+ view. addSubview ( bottomLineView)
64+ addConstraints ( )
65+ view. bringSubviewToFront ( bottomLineView)
4166 goTo ( startPage)
4267 }
4368}
@@ -56,7 +81,7 @@ extension PagesController {
5681 completion: { [ unowned self] finished in
5782 self . pagesDelegate? . pageViewController ( self ,
5883 setViewController: viewController,
59- atPage: currentIndex)
84+ atPage: self . currentIndex)
6085 } )
6186 if setNavigationTitle {
6287 title = viewController. title
@@ -151,13 +176,31 @@ extension PagesController {
151176 completion: { [ unowned self] finished in
152177 self . pagesDelegate? . pageViewController ( self ,
153178 setViewController: viewController,
154- atPage: currentIndex)
179+ atPage: self . currentIndex)
155180 } )
156181 if setNavigationTitle {
157182 title = viewController. title
158183 }
159184 }
160185 }
186+
187+ private func addConstraints( ) {
188+ view. addConstraint ( NSLayoutConstraint ( item: bottomLineView, attribute: . Bottom,
189+ relatedBy: . Equal, toItem: view, attribute: . Bottom,
190+ multiplier: 1 , constant: - Dimensions. bottomLineBottomMargin) )
191+
192+ view. addConstraint ( NSLayoutConstraint ( item: bottomLineView, attribute: . Left,
193+ relatedBy: . Equal, toItem: view, attribute: . Left,
194+ multiplier: 1 , constant: Dimensions . bottomLineSideMargin) )
195+
196+ view. addConstraint ( NSLayoutConstraint ( item: bottomLineView, attribute: . Right,
197+ relatedBy: . Equal, toItem: view, attribute: . Right,
198+ multiplier: 1 , constant: - Dimensions. bottomLineSideMargin) )
199+
200+ view. addConstraint ( NSLayoutConstraint ( item: bottomLineView, attribute: . Height,
201+ relatedBy: . Equal, toItem: nil , attribute: . NotAnAttribute,
202+ multiplier: 1 , constant: Dimensions . bottomLineHeight) )
203+ }
161204}
162205
163206extension Array {
@@ -179,4 +222,3 @@ func nextIndex(x: Int?) -> Int? {
179222func prevIndex( x: Int? ) - > Int? {
180223 return x. map { $0 - 1 }
181224}
182-
0 commit comments