class AccessibleButtonContainerView: UIView {
override var accessibilityLabel: String? {
get {
let combinedLabels = subviews.compactMap { view -> String? in
if let label = view as? UILabel {
return label.text
}
return view.accessibilityLabel
}.joined(separator: " ")
return combinedLabels.isEmpty ? nil : combinedLabels
}
set {
super.accessibilityLabel = newValue
}
}
override init(frame: CGRect) {
super.init(frame: frame)
setupAccessibility()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
setupAccessibility()
}
private func setupAccessibility() {
isAccessibilityElement = true
accessibilityTraits = .button
}
}