28 lines
1.0 KiB
Swift
28 lines
1.0 KiB
Swift
//
|
|
// UIView+Accessibility.swift
|
|
// VDS
|
|
//
|
|
// Created by Matt Bruce on 8/4/23.
|
|
//
|
|
|
|
import Foundation
|
|
import UIKit
|
|
|
|
extension UIView {
|
|
/// AccessibilityLabel helper for joining the accessibilityLabel property of all views passed in.
|
|
/// - Parameters:
|
|
/// - views: Array of Views that you want to join the accessibilityLabel.
|
|
/// - separator: Separator used between the accessibilityLabel for each UIView.
|
|
/// - Returns: Joined String.
|
|
public func combineAccessibilityLabel(for views: [UIView], separator: String = ", ") -> String? {
|
|
let labels = views.map({($0.accessibilityLabel?.isEmpty ?? true) ? nil : $0.accessibilityLabel}).compactMap({$0})
|
|
return labels.joined(separator: separator)
|
|
}
|
|
|
|
/// AccessibilityLabel helper for joining the accessibilityLabel property of all views passed in.
|
|
/// - Parameter views: Array of Views that you want to join the accessibilityLabel.
|
|
public func setAccessibilityLabel(for views: [UIView]) {
|
|
accessibilityLabel = combineAccessibilityLabel(for: views)
|
|
}
|
|
}
|