@@ -91,26 +91,36 @@ private extension SwitchControlViewController {
91
91
92
92
switchControls. forEach { addSubview ( $0) }
93
93
94
+ let switchTrait = UIAccessibilityTraits ( rawValue: 0x0020000000000000 )
95
+
94
96
// Add a fake switch that has the switch button trait only, but is not a UISwitch.
95
- fakeSwitchView. isAccessibilityElement = true
96
- fakeSwitchView. accessibilityLabel = " Fake Label "
97
- fakeSwitchView. accessibilityValue = " Value "
98
- fakeSwitchView. accessibilityTraits. insert ( UIAccessibilityTraits ( rawValue: 0x0020000000000000 ) )
99
- fakeSwitchView. frame. size = . init( width: 48 , height: 32 )
100
- fakeSwitchView. backgroundColor = . lightGray
101
- fakeSwitchView. layer. cornerRadius = 16
102
- addSubview ( fakeSwitchView)
103
-
104
- // Add a fake switch that has the switch button and button traits, but is not a UISwitch.
105
- fakeSwitchButton. isAccessibilityElement = true
106
- fakeSwitchButton. accessibilityLabel = " Fake Label "
107
- fakeSwitchButton. accessibilityValue = " Value "
108
- fakeSwitchButton. accessibilityTraits. insert ( . button)
109
- fakeSwitchButton. accessibilityTraits. insert ( UIAccessibilityTraits ( rawValue: 0x0020000000000000 ) )
110
- fakeSwitchButton. frame. size = . init( width: 48 , height: 32 )
111
- fakeSwitchButton. backgroundColor = . lightGray
112
- fakeSwitchButton. layer. cornerRadius = 16
113
- addSubview ( fakeSwitchButton)
97
+ for fakeSwitchView in fakeSwitchViews {
98
+ fakeSwitchView. isAccessibilityElement = true
99
+ fakeSwitchView. accessibilityLabel = " Fake Label "
100
+ fakeSwitchView. frame. size = . init( width: 48 , height: 32 )
101
+ fakeSwitchView. backgroundColor = . lightGray
102
+ fakeSwitchView. layer. cornerRadius = 16
103
+ }
104
+
105
+ fakeSwitchViews [ 0 ] . accessibilityValue = " 1 "
106
+ fakeSwitchViews [ 0 ] . accessibilityTraits = [ switchTrait, . button]
107
+
108
+ fakeSwitchViews [ 1 ] . accessibilityValue = " 0 "
109
+ fakeSwitchViews [ 1 ] . accessibilityTraits = [ switchTrait, . button]
110
+
111
+ fakeSwitchViews [ 2 ] . accessibilityValue = " 2 "
112
+ fakeSwitchViews [ 2 ] . accessibilityTraits = [ switchTrait, . button]
113
+
114
+ fakeSwitchViews [ 3 ] . accessibilityValue = " 1 "
115
+ fakeSwitchViews [ 3 ] . accessibilityTraits = [ switchTrait]
116
+
117
+ fakeSwitchViews [ 4 ] . accessibilityValue = " 3 "
118
+ fakeSwitchViews [ 4 ] . accessibilityTraits = [ switchTrait]
119
+
120
+ fakeSwitchViews [ 5 ] . accessibilityValue = " Value "
121
+ fakeSwitchViews [ 5 ] . accessibilityTraits = [ . button, switchTrait]
122
+
123
+ fakeSwitchViews. forEach { addSubview ( $0) }
114
124
}
115
125
116
126
@available ( * , unavailable)
@@ -122,11 +132,8 @@ private extension SwitchControlViewController {
122
132
123
133
private let switchControls : [ UISwitch ] = ( 0 ..< 9 ) . map { _ in UISwitch ( ) }
124
134
125
- /// UIView with the switch button trait that acts like a switch, but is not a UISwitch.
126
- private let fakeSwitchView : UIView = . init( )
127
-
128
- /// UIView with the button and switch button traits that acts like a switch, but is not a UISwitch.
129
- private let fakeSwitchButton : UIView = . init( )
135
+ /// `UIView`s with the switch button trait that act like a switch, but aren't actually switches.
136
+ private let fakeSwitchViews : [ UIView ] = ( 0 ..< 6 ) . map { _ in UIView ( ) }
130
137
131
138
// MARK: - UIView
132
139
@@ -136,18 +143,10 @@ private extension SwitchControlViewController {
136
143
let statusBarHeight = window? . windowScene? . statusBarManager? . statusBarFrame. height ?? 0
137
144
138
145
var distributionSpecifiers : [ ViewDistributionSpecifying ] = [ statusBarHeight. fixed, 1 . flexible ]
139
- for subview in switchControls {
146
+ for subview in ( switchControls + fakeSwitchViews ) {
140
147
distributionSpecifiers. append ( subview)
141
148
distributionSpecifiers. append ( 1 . flexible)
142
149
}
143
- distributionSpecifiers. append (
144
- contentsOf: [
145
- fakeSwitchView. distributionItem,
146
- 1 . flexible,
147
- fakeSwitchButton. distributionItem,
148
- 1 . flexible,
149
- ]
150
- )
151
150
applyVerticalSubviewDistribution ( distributionSpecifiers)
152
151
}
153
152
0 commit comments