@@ -19,65 +19,86 @@ import UIKit
19
19
20
20
final class DefaultControlsViewController : AccessibilityViewController {
21
21
22
- // MARK: - Private Properties
22
+ // MARK: - UIViewController
23
23
24
- private let datePicker : UIDatePicker = . init( )
24
+ override func loadView( ) {
25
+ view = View ( )
26
+ }
25
27
26
- private let pageControl : UIPageControl = . init ( )
28
+ }
27
29
28
- private let segmentedControl : UISegmentedControl = . init ( )
30
+ // MARK: -
29
31
30
- private let slider : UISlider = . init ( )
32
+ private extension DefaultControlsViewController {
31
33
32
- private let stepper : UIStepper = . init ( )
34
+ final class View : UIView {
33
35
34
- private var controls : [ UIControl ] {
35
- return [
36
- datePicker,
37
- pageControl,
38
- segmentedControl,
39
- slider,
40
- stepper,
41
- ]
42
- }
36
+ // MARK: - Life Cycle
43
37
44
- // MARK: - UIViewController
38
+ override init ( frame: CGRect ) {
39
+ super. init ( frame: frame)
45
40
46
- override func viewDidLoad( ) {
47
- super. viewDidLoad ( )
41
+ pageControl. numberOfPages = 3
42
+ pageControl. pageIndicatorTintColor = . lightGray
43
+ pageControl. currentPageIndicatorTintColor = . black
48
44
49
- pageControl . numberOfPages = 3
50
- pageControl . pageIndicatorTintColor = . lightGray
51
- pageControl . currentPageIndicatorTintColor = . black
45
+ segmentedControl . insertSegment ( withTitle : " Segment A " , at : 0 , animated : false )
46
+ segmentedControl . insertSegment ( withTitle : " Segment B " , at : 1 , animated : false )
47
+ segmentedControl . insertSegment ( withTitle : " Segment C " , at : 2 , animated : false )
52
48
53
- segmentedControl . insertSegment ( withTitle : " Segment A " , at : 0 , animated : false )
54
- segmentedControl . insertSegment ( withTitle : " Segment B " , at : 1 , animated : false )
55
- segmentedControl . insertSegment ( withTitle : " Segment C " , at : 2 , animated : false )
49
+ slider . minimumValue = 0
50
+ slider . maximumValue = 100
51
+ slider . value = 75
56
52
57
- slider . minimumValue = 0
58
- slider . maximumValue = 100
59
- slider . value = 75
53
+ stepper . minimumValue = - 1
54
+ stepper . maximumValue = 1
55
+ stepper . value = 0
60
56
61
- stepper. minimumValue = - 1
62
- stepper. maximumValue = 1
63
- stepper. value = 0
57
+ controls. forEach { addSubview ( $0) }
58
+ }
64
59
65
- controls. forEach { view. addSubview ( $0) }
66
- }
60
+ @available ( * , unavailable)
61
+ required init ? ( coder: NSCoder ) {
62
+ fatalError ( " init(coder:) has not been implemented " )
63
+ }
64
+
65
+ // MARK: - Private Properties
67
66
68
- override func viewDidLayoutSubviews( ) {
69
- super. viewDidLayoutSubviews ( )
67
+ private let datePicker : UIDatePicker = . init( )
70
68
71
- controls . forEach { $0 . sizeToFit ( ) }
69
+ private let pageControl : UIPageControl = . init ( )
72
70
73
- let statusBarHeight = UIApplication . shared . statusBarFrame . height
71
+ private let segmentedControl : UISegmentedControl = . init ( )
74
72
75
- var distributionSpecifiers : [ ViewDistributionSpecifying ] = [ statusBarHeight. fixed, 1 . flexible ]
76
- for subview in controls {
77
- distributionSpecifiers. append ( subview)
78
- distributionSpecifiers. append ( 1 . flexible)
73
+ private let slider : UISlider = . init( )
74
+
75
+ private let stepper : UIStepper = . init( )
76
+
77
+ private var controls : [ UIControl ] {
78
+ return [
79
+ datePicker,
80
+ pageControl,
81
+ segmentedControl,
82
+ slider,
83
+ stepper,
84
+ ]
85
+ }
86
+
87
+ // MARK: - UIView
88
+
89
+ override func layoutSubviews( ) {
90
+ controls. forEach { $0. sizeToFit ( ) }
91
+
92
+ let statusBarHeight = window? . windowScene? . statusBarManager? . statusBarFrame. height ?? 0
93
+
94
+ var distributionSpecifiers : [ ViewDistributionSpecifying ] = [ statusBarHeight. fixed, 1 . flexible ]
95
+ for subview in controls {
96
+ distributionSpecifiers. append ( subview)
97
+ distributionSpecifiers. append ( 1 . flexible)
98
+ }
99
+ applySubviewDistribution ( distributionSpecifiers)
79
100
}
80
- view . applySubviewDistribution ( distributionSpecifiers )
101
+
81
102
}
82
103
83
104
}
0 commit comments