@@ -21,36 +21,16 @@ final class InvertColorsViewController: AccessibilityViewController {
21
21
22
22
// MARK: - Private Properties
23
23
24
- private let nestedSubviews : [ UIView ] = ( 0 ..< 5 ) . map { _ in UIView ( ) }
25
-
26
- private let statusLabel : UILabel = . init( )
27
-
28
24
private var notificationObserver : AnyObject ?
29
25
30
- // MARK: - UIViewController
31
-
32
- override func viewDidLoad( ) {
33
- super. viewDidLoad ( )
34
-
35
- let nestedViews : [ UIView ] = [ view] + nestedSubviews
36
- for (view, subview) in zip ( nestedViews. dropLast ( ) , nestedViews. dropFirst ( ) ) {
37
- view. addSubview ( subview)
38
- }
39
-
40
- nestedSubviews [ 0 ] . backgroundColor = . red
41
-
42
- nestedSubviews [ 1 ] . backgroundColor = . blue
43
-
44
- nestedSubviews [ 2 ] . backgroundColor = . green
45
- nestedSubviews [ 2 ] . accessibilityIgnoresInvertColors = true
46
-
47
- nestedSubviews [ 3 ] . backgroundColor = . yellow
26
+ private var rootView : View {
27
+ return view as! View
28
+ }
48
29
49
- nestedSubviews [ 4 ] . backgroundColor = . purple
50
- nestedSubviews [ 4 ] . accessibilityIgnoresInvertColors = true
30
+ // MARK: - UIViewController
51
31
52
- statusLabel . textColor = . white
53
- nestedSubviews [ 2 ] . addSubview ( statusLabel )
32
+ override func loadView ( ) {
33
+ view = View ( )
54
34
}
55
35
56
36
override func viewWillAppear( _ animated: Bool ) {
@@ -76,22 +56,70 @@ final class InvertColorsViewController: AccessibilityViewController {
76
56
}
77
57
}
78
58
79
- override func viewDidLayoutSubviews( ) {
80
- super. viewDidLayoutSubviews ( )
59
+ // MARK: - Private Methods
60
+
61
+ private func updateStatusLabel( ) {
62
+ rootView. statusLabel. text = UIAccessibility . isInvertColorsEnabled ? " Enabled " : " Disabled "
63
+ rootView. setNeedsLayout ( )
64
+ }
65
+
66
+ }
67
+
68
+ // MARK: -
69
+
70
+ private extension InvertColorsViewController {
71
+
72
+ final class View : UIView {
81
73
82
- for view in nestedSubviews {
83
- view. frame = view. superview!. bounds. inset ( left: 30 , top: 60 , right: 30 , bottom: 60 )
74
+ // MARK: - Life Cycle
75
+
76
+ override init ( frame: CGRect ) {
77
+ super. init ( frame: frame)
78
+
79
+ let nestedViews : [ UIView ] = [ self ] + nestedSubviews
80
+ for (view, subview) in zip ( nestedViews. dropLast ( ) , nestedViews. dropFirst ( ) ) {
81
+ view. addSubview ( subview)
82
+ }
83
+
84
+ nestedSubviews [ 0 ] . backgroundColor = . red
85
+
86
+ nestedSubviews [ 1 ] . backgroundColor = . blue
87
+
88
+ nestedSubviews [ 2 ] . backgroundColor = . green
89
+ nestedSubviews [ 2 ] . accessibilityIgnoresInvertColors = true
90
+
91
+ nestedSubviews [ 3 ] . backgroundColor = . yellow
92
+
93
+ nestedSubviews [ 4 ] . backgroundColor = . purple
94
+ nestedSubviews [ 4 ] . accessibilityIgnoresInvertColors = true
95
+
96
+ statusLabel. textColor = . white
97
+ nestedSubviews [ 2 ] . addSubview ( statusLabel)
84
98
}
85
99
86
- statusLabel. sizeToFit ( )
87
- statusLabel. alignToSuperview ( . topCenter, inset: 20 )
88
- }
100
+ @available ( * , unavailable)
101
+ required init ? ( coder: NSCoder ) {
102
+ fatalError ( " init(coder:) has not been implemented " )
103
+ }
89
104
90
- // MARK: - Private Methods
105
+ // MARK: - Private Properties
106
+
107
+ private let nestedSubviews : [ UIView ] = ( 0 ..< 5 ) . map { _ in UIView ( ) }
108
+
109
+ let statusLabel : UILabel = . init( )
110
+
111
+ // MARK: - UIView
112
+
113
+ override func layoutSubviews( ) {
114
+ let nestedViews : [ UIView ] = [ self ] + nestedSubviews
115
+ for (containingView, subview) in zip ( nestedViews. dropLast ( ) , nestedViews. dropFirst ( ) ) {
116
+ subview. frame = containingView. bounds. inset ( left: 30 , top: 60 , right: 30 , bottom: 60 )
117
+ }
118
+
119
+ statusLabel. sizeToFit ( )
120
+ statusLabel. alignToSuperview ( . topCenter, inset: 20 )
121
+ }
91
122
92
- private func updateStatusLabel( ) {
93
- statusLabel. text = UIAccessibility . isInvertColorsEnabled ? " Enabled " : " Disabled "
94
- view. setNeedsLayout ( )
95
123
}
96
124
97
125
}
0 commit comments