Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize DefaultControlsViewController #135

Merged
merged 1 commit into from
Aug 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 62 additions & 41 deletions Example/AccessibilitySnapshot/DefaultControlsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,65 +19,86 @@ import UIKit

final class DefaultControlsViewController: AccessibilityViewController {

// MARK: - Private Properties
// MARK: - UIViewController

private let datePicker: UIDatePicker = .init()
override func loadView() {
view = View()
}

private let pageControl: UIPageControl = .init()
}

private let segmentedControl: UISegmentedControl = .init()
// MARK: -

private let slider: UISlider = .init()
private extension DefaultControlsViewController {

private let stepper: UIStepper = .init()
final class View: UIView {

private var controls: [UIControl] {
return [
datePicker,
pageControl,
segmentedControl,
slider,
stepper,
]
}
// MARK: - Life Cycle

// MARK: - UIViewController
override init(frame: CGRect) {
super.init(frame: frame)

override func viewDidLoad() {
super.viewDidLoad()
pageControl.numberOfPages = 3
pageControl.pageIndicatorTintColor = .lightGray
pageControl.currentPageIndicatorTintColor = .black

pageControl.numberOfPages = 3
pageControl.pageIndicatorTintColor = .lightGray
pageControl.currentPageIndicatorTintColor = .black
segmentedControl.insertSegment(withTitle: "Segment A", at: 0, animated: false)
segmentedControl.insertSegment(withTitle: "Segment B", at: 1, animated: false)
segmentedControl.insertSegment(withTitle: "Segment C", at: 2, animated: false)

segmentedControl.insertSegment(withTitle: "Segment A", at: 0, animated: false)
segmentedControl.insertSegment(withTitle: "Segment B", at: 1, animated: false)
segmentedControl.insertSegment(withTitle: "Segment C", at: 2, animated: false)
slider.minimumValue = 0
slider.maximumValue = 100
slider.value = 75

slider.minimumValue = 0
slider.maximumValue = 100
slider.value = 75
stepper.minimumValue = -1
stepper.maximumValue = 1
stepper.value = 0

stepper.minimumValue = -1
stepper.maximumValue = 1
stepper.value = 0
controls.forEach { addSubview($0) }
}

controls.forEach { view.addSubview($0) }
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

// MARK: - Private Properties

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
private let datePicker: UIDatePicker = .init()

controls.forEach { $0.sizeToFit() }
private let pageControl: UIPageControl = .init()

let statusBarHeight = UIApplication.shared.statusBarFrame.height
private let segmentedControl: UISegmentedControl = .init()

var distributionSpecifiers: [ViewDistributionSpecifying] = [ statusBarHeight.fixed, 1.flexible ]
for subview in controls {
distributionSpecifiers.append(subview)
distributionSpecifiers.append(1.flexible)
private let slider: UISlider = .init()

private let stepper: UIStepper = .init()

private var controls: [UIControl] {
return [
datePicker,
pageControl,
segmentedControl,
slider,
stepper,
]
}

// MARK: - UIView

override func layoutSubviews() {
controls.forEach { $0.sizeToFit() }

let statusBarHeight = window?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0

var distributionSpecifiers: [ViewDistributionSpecifying] = [ statusBarHeight.fixed, 1.flexible ]
for subview in controls {
distributionSpecifiers.append(subview)
distributionSpecifiers.append(1.flexible)
}
applySubviewDistribution(distributionSpecifiers)
}
view.applySubviewDistribution(distributionSpecifiers)

}

}