@@ -90,7 +90,6 @@ extension NavBarBackButtonAccessibilityTraitsViewController {
90
90
91
91
extension NavBarBackButtonAccessibilityTraitsViewController {
92
92
93
-
94
93
final class View : UIView {
95
94
96
95
// MARK: - Life Cycle
@@ -130,242 +129,3 @@ extension NavBarBackButtonAccessibilityTraitsViewController {
130
129
}
131
130
132
131
}
133
-
134
- // MARK: -
135
-
136
- private final class TabBarTraitView : UIView {
137
-
138
- // MARK: - Private
139
-
140
- private enum Metrics {
141
- static let height : CGFloat = 40
142
- }
143
-
144
- // MARK: - Life Cycle
145
-
146
- override init ( frame: CGRect ) {
147
- let standardTab = UIButton ( )
148
- standardTab. setTitle ( " A " , for: . normal)
149
- standardTab. setTitleColor ( . black, for: . normal)
150
- standardTab. accessibilityLabel = " Item A "
151
-
152
- let selectedTab = UIButton ( )
153
- selectedTab. setTitle ( " B " , for: . normal)
154
- selectedTab. setTitleColor ( . black, for: . normal)
155
- selectedTab. isSelected = true
156
- selectedTab. accessibilityLabel = " Item B "
157
-
158
- let disabledTab = UIButton ( )
159
- disabledTab. setTitle ( " C " , for: . normal)
160
- disabledTab. setTitleColor ( . lightGray, for: . disabled)
161
- disabledTab. isEnabled = false
162
- disabledTab. accessibilityLabel = " Item C "
163
-
164
- let untitledTab = UIButton ( )
165
-
166
- let nestedTab = MultiElementButton ( isContainer: false )
167
-
168
- let nestedContainerTab = MultiElementButton ( isContainer: true )
169
-
170
- let nonAccessibileTab = UIButton ( )
171
- nonAccessibileTab. setTitle ( " G " , for: . normal)
172
- nonAccessibileTab. setTitleColor ( . black, for: . normal)
173
- nonAccessibileTab. isAccessibilityElement = false
174
- nonAccessibileTab. titleLabel? . isAccessibilityElement = false
175
-
176
- let allTheTraitsTab = UIButton ( )
177
- allTheTraitsTab. setTitle ( " H " , for: . normal)
178
- allTheTraitsTab. setTitleColor ( . black, for: . normal)
179
- allTheTraitsTab. accessibilityTraits. insert ( . notEnabled)
180
- allTheTraitsTab. accessibilityTraits. insert ( . header)
181
- allTheTraitsTab. accessibilityTraits. insert ( . link)
182
- allTheTraitsTab. accessibilityTraits. insert ( . adjustable)
183
- allTheTraitsTab. accessibilityTraits. insert ( . image)
184
- allTheTraitsTab. accessibilityTraits. insert ( . searchField)
185
-
186
- self . tabs = [ standardTab, selectedTab, disabledTab, untitledTab, nestedTab, nestedContainerTab, nonAccessibileTab, allTheTraitsTab]
187
-
188
- super. init ( frame: frame)
189
-
190
- tabs. shuffled ( ) . forEach ( addSubview)
191
- }
192
-
193
- @available ( * , unavailable)
194
- required init ? ( coder: NSCoder ) {
195
- fatalError ( " init(coder:) has not been implemented " )
196
- }
197
-
198
- // MARK: - Private Properties
199
-
200
- private let tabs : [ UIView ]
201
-
202
- // MARK: - UIView
203
-
204
- override func layoutSubviews( ) {
205
- tabs. forEach { $0. frame. size. height = bounds. height }
206
- horizontallySpreadSubviews ( tabs, margin: 0 )
207
- }
208
-
209
- override func sizeThatFits( _ size: CGSize ) -> CGSize {
210
- return CGSize ( width: size. width, height: Metrics . height)
211
- }
212
-
213
- // MARK: - UIAccessibility
214
-
215
- override var accessibilityTraits : UIAccessibilityTraits {
216
- get {
217
- return super. accessibilityTraits. union ( . tabBar)
218
- }
219
- set {
220
- super. accessibilityTraits = newValue
221
- }
222
- }
223
-
224
- // MARK: - Private Types
225
-
226
- private final class MultiElementButton : UIButton {
227
-
228
- // MARK: - Life Cycle
229
-
230
- init ( isContainer: Bool ) {
231
- super. init ( frame: . zero)
232
-
233
- middleLabel. text = " 2 "
234
- addSubview ( middleLabel)
235
-
236
- rightLabel. text = " 3 "
237
- outerLabelContainer. addSubview ( rightLabel)
238
-
239
- leftLabel. text = " 1 "
240
- outerLabelContainer. addSubview ( leftLabel)
241
- addSubview ( outerLabelContainer)
242
-
243
- isAccessibilityElement = false
244
-
245
- if isContainer {
246
- accessibilityElements = [ middleLabel, leftLabel, rightLabel]
247
- }
248
- }
249
-
250
- @available ( * , unavailable)
251
- required init ? ( coder: NSCoder ) {
252
- fatalError ( " init(coder:) has not been implemented " )
253
- }
254
-
255
- // MARK: - Private Properties
256
-
257
- private let leftLabel : UILabel = . init( )
258
-
259
- private let middleLabel : UILabel = . init( )
260
-
261
- private let rightLabel : UILabel = . init( )
262
-
263
- private let outerLabelContainer : UIView = . init( )
264
-
265
- // MARK: - UIView
266
-
267
- override func layoutSubviews( ) {
268
- outerLabelContainer. frame = bounds
269
-
270
- leftLabel. sizeToFit ( )
271
- leftLabel. capInsetsAlignmentProxy. align ( withSuperview: . leftCenter, inset: 4 )
272
-
273
- rightLabel. sizeToFit ( )
274
- rightLabel. capInsetsAlignmentProxy. align ( withSuperview: . rightCenter, inset: 4 )
275
-
276
- middleLabel. sizeToFit ( )
277
- middleLabel. capInsetsAlignmentProxy. align ( withSuperview: . center)
278
- }
279
-
280
- }
281
-
282
- }
283
-
284
- // MARK: -
285
-
286
- private final class TabBarTraitContainerView : UIView {
287
-
288
- // MARK: - Private
289
-
290
- private enum Metrics {
291
- static let height : CGFloat = 40
292
- }
293
-
294
- // MARK: - Life Cycle
295
-
296
- override init ( frame: CGRect ) {
297
- // There is one more label than there are elements, to test that the tab count comes from the number of
298
- // elements, not the number of subviews.
299
- self . itemLabels = ( 0 ..< 5 ) . map { index in
300
- let label = UILabel ( )
301
- label. text = " \( [ " A " , " B " , " C " , " D " , " E " , " - " ] [ index] ) "
302
- label. textAlignment = . center
303
- return label
304
- }
305
-
306
- super. init ( frame: frame)
307
-
308
- let standardElement = UIAccessibilityElement ( accessibilityContainer: self )
309
- standardElement. accessibilityLabel = " Item A "
310
-
311
- let selectedElement = UIAccessibilityElement ( accessibilityContainer: self )
312
- selectedElement. accessibilityLabel = " Item B "
313
- selectedElement. accessibilityTraits. insert ( . selected)
314
-
315
- let disabledElement = UIAccessibilityElement ( accessibilityContainer: self )
316
- disabledElement. accessibilityLabel = " Item C "
317
- disabledElement. accessibilityTraits. insert ( . notEnabled)
318
-
319
- let untitledElement = UIAccessibilityElement ( accessibilityContainer: self )
320
-
321
- let allTheTraitsElement = UIAccessibilityElement ( accessibilityContainer: self )
322
- allTheTraitsElement. accessibilityLabel = " Item E "
323
- allTheTraitsElement. accessibilityTraits. insert ( . notEnabled)
324
- allTheTraitsElement. accessibilityTraits. insert ( . header)
325
- allTheTraitsElement. accessibilityTraits. insert ( . link)
326
- allTheTraitsElement. accessibilityTraits. insert ( . adjustable)
327
- allTheTraitsElement. accessibilityTraits. insert ( . image)
328
- allTheTraitsElement. accessibilityTraits. insert ( . searchField)
329
-
330
- accessibilityElements = [ standardElement, selectedElement, disabledElement, untitledElement, allTheTraitsElement]
331
-
332
- itemLabels. shuffled ( ) . forEach ( addSubview)
333
- }
334
-
335
- @available ( * , unavailable)
336
- required init ? ( coder: NSCoder ) {
337
- fatalError ( " init(coder:) has not been implemented " )
338
- }
339
-
340
- // MARK: - Private Properties
341
-
342
- private let itemLabels : [ UILabel ]
343
-
344
- // MARK: - UIView
345
-
346
- override func sizeThatFits( _ size: CGSize ) -> CGSize {
347
- return CGSize ( width: size. width, height: Metrics . height)
348
- }
349
-
350
- override func layoutSubviews( ) {
351
- itemLabels. forEach { $0. frame. size. height = bounds. height }
352
-
353
- horizontallySpreadSubviews ( itemLabels, margin: 0 )
354
-
355
- for (label, element) in zip ( itemLabels, accessibilityElements as! [ UIAccessibilityElement ] ) {
356
- element. accessibilityFrameInContainerSpace = label. frame
357
- }
358
- }
359
-
360
- // MARK: - UIAccessibility
361
-
362
- override var accessibilityTraits : UIAccessibilityTraits {
363
- get {
364
- return super. accessibilityTraits. union ( . tabBar)
365
- }
366
- set {
367
- super. accessibilityTraits = newValue
368
- }
369
- }
370
-
371
- }
0 commit comments