Skip to content

Instantly share code, notes, and snippets.

@mecid
Last active February 11, 2019 08:33
Show Gist options
  • Save mecid/fc365877eda941c14402349591ffff8f to your computer and use it in GitHub Desktop.
Save mecid/fc365877eda941c14402349591ffff8f to your computer and use it in GitHub Desktop.
saccessibility8.swift
override func layoutSubviews() {
super.layoutSubviews()
guard let max = values.max() else { return }
subviews.forEach { $0.removeFromSuperview() }
var x: CGFloat = Layout.barWidth
let maxHeight: CGFloat = bounds.height * Layout.maxHeightRatio
var accessibilityElements: [UIAccessibilityElement] = []
values.forEach { value in
let height = CGFloat(value / max) * maxHeight
let y = bounds.height - height - safeAreaInsets.bottom
let frame = CGRect(x: x, y: y, width: Layout.barWidth, height: height)
let bar = UIView(frame: frame)
bar.backgroundColor = .gray
addSubview(bar)
x = bar.frame.maxX + Layout.barWidth / 2
let element = UIAccessibilityElement(accessibilityContainer: self)
element.accessibilityFrameInContainerSpace = frame
element.accessibilityValue = String(value)
accessibilityElements.append(element)
}
self.accessibilityElements = accessibilityElements
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment