|
| 1 | +// |
| 2 | +// DebugTextPreviewViewController.swift |
| 3 | +// safesafe |
| 4 | +// |
| 5 | +// Created by Lukasz szyszkowski on 07/10/2020. |
| 6 | +// |
| 7 | + |
| 8 | +import UIKit |
| 9 | + |
| 10 | +final class DebugTextPreviewViewController: UIViewController { |
| 11 | + |
| 12 | + private enum Constants { |
| 13 | + static let closeButtonInsets = UIEdgeInsets(top: 20.0, left: 20.0, bottom: .zero, right: .zero) |
| 14 | + static let closeButtonSize = CGSize(width: 22.0, height: 22.0) |
| 15 | + static let titleLabelInsets = UIEdgeInsets(top: 20, left: .zero, bottom: 15.0, right: .zero) |
| 16 | + static let titleFont: UIFont = .systemFont(ofSize: 18.0, weight: .bold) |
| 17 | + static let textViewFont: UIFont = .systemFont(ofSize: 12) |
| 18 | + } |
| 19 | + |
| 20 | + private let closeButton = UIButton() |
| 21 | + private let titleLabel = UILabel() |
| 22 | + private let textView = UITextView() |
| 23 | + private let text: String |
| 24 | + |
| 25 | + required init?(coder: NSCoder) { |
| 26 | + fatalError("has not been implemented yet") |
| 27 | + } |
| 28 | + |
| 29 | + init(with text: String) { |
| 30 | + self.text = text |
| 31 | + super.init(nibName: nil, bundle: nil) |
| 32 | + } |
| 33 | + |
| 34 | + override func viewDidLoad() { |
| 35 | + super.viewDidLoad() |
| 36 | + |
| 37 | + setup() |
| 38 | + layout() |
| 39 | + } |
| 40 | + |
| 41 | + override func viewWillAppear(_ animated: Bool) { |
| 42 | + super.viewWillAppear(animated) |
| 43 | + textView.text = text |
| 44 | + } |
| 45 | + |
| 46 | + private func setup() { |
| 47 | + view.backgroundColor = .white |
| 48 | + view.addSubview(textView) |
| 49 | + setupCloseButton() |
| 50 | + setupTitleLabel() |
| 51 | + setupTextView() |
| 52 | + } |
| 53 | + |
| 54 | + private func setupCloseButton() { |
| 55 | + closeButton.translatesAutoresizingMaskIntoConstraints = false |
| 56 | + closeButton.setImage(#imageLiteral(resourceName: "close_icon"), for: .normal) |
| 57 | + closeButton.tintColor = .black |
| 58 | + closeButton.addTarget(self, action: #selector(closeButtonTap), for: .touchUpInside) |
| 59 | + view.addSubview(closeButton) |
| 60 | + } |
| 61 | + |
| 62 | + private func setupTitleLabel() { |
| 63 | + titleLabel.translatesAutoresizingMaskIntoConstraints = false |
| 64 | + titleLabel.textColor = .black |
| 65 | + titleLabel.font = Constants.titleFont |
| 66 | + titleLabel.textAlignment = .center |
| 67 | + titleLabel.text = DebugViewModel.Texts.previewTitle |
| 68 | + view.addSubview(titleLabel) |
| 69 | + } |
| 70 | + |
| 71 | + private func setupTextView() { |
| 72 | + textView.font = Constants.textViewFont |
| 73 | + view.addSubview(textView) |
| 74 | + } |
| 75 | + |
| 76 | + private func layout() { |
| 77 | + closeButton.snp.makeConstraints { maker in |
| 78 | + maker.size.equalTo(Constants.closeButtonSize) |
| 79 | + maker.left.top.equalToSuperview().inset(Constants.closeButtonInsets) |
| 80 | + } |
| 81 | + |
| 82 | + titleLabel.snp.makeConstraints { maker in |
| 83 | + maker.centerX.equalToSuperview() |
| 84 | + maker.top.equalToSuperview().inset(Constants.titleLabelInsets) |
| 85 | + } |
| 86 | + |
| 87 | + textView.snp.makeConstraints { maker in |
| 88 | + maker.leading.trailing.bottom.equalToSuperview() |
| 89 | + maker.top.equalTo(titleLabel.snp.bottom) |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + @objc private func closeButtonTap(sender: UIButton) { |
| 94 | + dismiss(animated: true) |
| 95 | + } |
| 96 | + |
| 97 | +} |
0 commit comments