Last active
February 11, 2019 08:33
-
-
Save mecid/fc365877eda941c14402349591ffff8f to your computer and use it in GitHub Desktop.
saccessibility8.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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