|
| 1 | +// |
| 2 | +// Copyright 2021 Square Inc. |
| 3 | +// |
| 4 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// |
| 8 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +// |
| 10 | +// Unless required by applicable law or agreed to in writing, software |
| 11 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +// See the License for the specific language governing permissions and |
| 14 | +// limitations under the License. |
| 15 | +// |
| 16 | + |
| 17 | +import Paralayout |
| 18 | +import UIKit |
| 19 | + |
| 20 | +final class TextInputsViewController: AccessibilityViewController { |
| 21 | + |
| 22 | + // MARK: - Private Properties |
| 23 | + |
| 24 | + private let textFieldEmpty: UITextField = .init() |
| 25 | + |
| 26 | + private let textFieldWithPlaceholder: UITextField = .init() |
| 27 | + |
| 28 | + private let textFieldWithText: UITextField = .init() |
| 29 | + |
| 30 | + private let textViewEmpty: UITextView = .init() |
| 31 | + |
| 32 | + private let textViewWithText: UITextView = .init() |
| 33 | + |
| 34 | + private var textInputViews: [UIView] { |
| 35 | + return [ |
| 36 | + textFieldEmpty, |
| 37 | + textFieldWithPlaceholder, |
| 38 | + textFieldWithText, |
| 39 | + textViewEmpty, |
| 40 | + textViewWithText, |
| 41 | + ] |
| 42 | + } |
| 43 | + |
| 44 | + // MARK: - UIViewController |
| 45 | + |
| 46 | + override func viewDidLoad() { |
| 47 | + super.viewDidLoad() |
| 48 | + |
| 49 | + textFieldWithPlaceholder.placeholder = "Some placeholder text" |
| 50 | + |
| 51 | + textFieldWithText.text = "Hello from Text Field" |
| 52 | + |
| 53 | + textViewWithText.text = "Hello from Text View" |
| 54 | + |
| 55 | + textInputViews.forEach { |
| 56 | + $0.layer.borderWidth = 1.0 |
| 57 | + $0.layer.borderColor = UIColor.lightGray.cgColor |
| 58 | + view.addSubview($0) |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + override func viewDidLayoutSubviews() { |
| 63 | + super.viewDidLayoutSubviews() |
| 64 | + |
| 65 | + textInputViews.forEach { $0.frame.size = CGSize(width: 250, height: 30) } |
| 66 | + |
| 67 | + let statusBarHeight = view.window?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0 |
| 68 | + |
| 69 | + var distributionSpecifiers: [ViewDistributionSpecifying] = [ statusBarHeight.fixed, 1.flexible ] |
| 70 | + for subview in textInputViews { |
| 71 | + distributionSpecifiers.append(subview) |
| 72 | + distributionSpecifiers.append(1.flexible) |
| 73 | + } |
| 74 | + view.applyVerticalSubviewDistribution(distributionSpecifiers) |
| 75 | + |
| 76 | + textViewWithText.accessibilityFrame = textViewWithText.frame |
| 77 | + } |
| 78 | + |
| 79 | +} |
0 commit comments