|
| 1 | +// |
| 2 | +// CheckMessagesViewController.swift |
| 3 | +// Deartoday |
| 4 | +// |
| 5 | +// Created by 이경민 on 2022/08/11. |
| 6 | +// |
| 7 | + |
| 8 | +import UIKit |
| 9 | + |
| 10 | +import SnapKit |
| 11 | +import Then |
| 12 | + |
| 13 | +final class CheckMessagesViewController: UIViewController { |
| 14 | + |
| 15 | + // MARK: - Property |
| 16 | + // MARK: - UI Property |
| 17 | + |
| 18 | + private let navigationView = UIView().then { |
| 19 | + $0.backgroundColor = .clear |
| 20 | + } |
| 21 | + |
| 22 | + private let backButton = UIButton().then { |
| 23 | + $0.setImage(Constant.Image.icBack, for: .normal) |
| 24 | + $0.addTarget(self, action: #selector(backButtonDidTap), for: .touchUpInside) |
| 25 | + } |
| 26 | + |
| 27 | + private let messageImageView = UIImageView().then { |
| 28 | + $0.image = Constant.Image.imgMemoBundle |
| 29 | + } |
| 30 | + |
| 31 | + private let titleLabel = UILabel().then { |
| 32 | + $0.text = "나의 메시지" |
| 33 | + $0.font = .h1 |
| 34 | + $0.textColor = .darkGray01 |
| 35 | + $0.setPartialLabelColor(targetStringList: ["메시지"], color: .blue02) |
| 36 | + } |
| 37 | + |
| 38 | + private let descriptionLabel = UILabel().then { |
| 39 | + $0.text = "미래의 나로부터 도착한 메시지를 확인해보세요" |
| 40 | + $0.font = .caption2 |
| 41 | + $0.textColor = .gray00 |
| 42 | + } |
| 43 | + |
| 44 | + private let emptyView = UIView().then { |
| 45 | + $0.isHidden = false |
| 46 | + $0.backgroundColor = .clear |
| 47 | + } |
| 48 | + |
| 49 | + private let emptyMessageImageView = UIImageView().then { |
| 50 | + $0.image = Constant.Image.imgMemoempty |
| 51 | + } |
| 52 | + |
| 53 | + private let emptyDescriptionLabel = UILabel().then { |
| 54 | + $0.text = "아직 나에게 도착한 메시지가 없어요!\n지금 바로 시간 여행을 떠나볼까요?" |
| 55 | + $0.numberOfLines = 0 |
| 56 | + $0.font = .caption2 |
| 57 | + $0.textColor = .gray01 |
| 58 | + $0.setTextWithLineHeight(text: $0.text, lineHeight: 22) |
| 59 | + } |
| 60 | + |
| 61 | + private let timeTravelButton = DDSButton().then { |
| 62 | + $0.text = "시간 여행 떠나기" |
| 63 | + $0.hasLeftIcon = true |
| 64 | + $0.style = .present |
| 65 | + } |
| 66 | + |
| 67 | + private let timeTravelView = UIView().then { |
| 68 | + $0.backgroundColor = .clear |
| 69 | + $0.isUserInteractionEnabled = true |
| 70 | + } |
| 71 | + |
| 72 | + // MARK: - Life Cycle |
| 73 | + |
| 74 | + override func viewDidLoad() { |
| 75 | + super.viewDidLoad() |
| 76 | + setUI() |
| 77 | + setLayout() |
| 78 | + setGesture() |
| 79 | + } |
| 80 | + |
| 81 | + // MARK: - @objc |
| 82 | + |
| 83 | + @objc private func backButtonDidTap() { |
| 84 | + navigationController?.popViewController(animated: true) |
| 85 | + } |
| 86 | + |
| 87 | + @objc private func timeTravelButtonDidTap() { |
| 88 | + let timeTravel = TimeTravelViewController() |
| 89 | + timeTravel.modalTransitionStyle = .crossDissolve |
| 90 | + timeTravel.modalPresentationStyle = .fullScreen |
| 91 | + present(timeTravel, animated: true) { |
| 92 | + self.navigationController?.popViewController(animated: false) |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + // MARK: - Custom Method |
| 97 | + |
| 98 | + private func setUI() { |
| 99 | + view.backgroundColor = .white |
| 100 | + } |
| 101 | + |
| 102 | + private func setLayout() { |
| 103 | + setHierarchy() |
| 104 | + setConstraint() |
| 105 | + } |
| 106 | + |
| 107 | + private func setHierarchy() { |
| 108 | + view.addSubviews([navigationView, emptyView]) |
| 109 | + navigationView.addSubviews([backButton, messageImageView, |
| 110 | + titleLabel, descriptionLabel]) |
| 111 | + emptyView.addSubviews([emptyMessageImageView, emptyDescriptionLabel, timeTravelButton]) |
| 112 | + timeTravelButton.addSubview(timeTravelView) |
| 113 | + } |
| 114 | + |
| 115 | + private func setConstraint() { |
| 116 | + setNavigationBarConstraint() |
| 117 | + setEmptyViewContraint() |
| 118 | + } |
| 119 | + |
| 120 | + private func setGesture() { |
| 121 | + let gesture = UITapGestureRecognizer(target: self, action: #selector(timeTravelButtonDidTap)) |
| 122 | + timeTravelView.addGestureRecognizer(gesture) |
| 123 | + } |
| 124 | +} |
| 125 | + |
| 126 | +// MARK: - Constraints |
| 127 | + |
| 128 | +extension CheckMessagesViewController { |
| 129 | + private func setNavigationBarConstraint() { |
| 130 | + navigationView.snp.makeConstraints { make in |
| 131 | + make.top.leading.trailing.equalTo(view.safeAreaLayoutGuide).inset(0) |
| 132 | + make.height.equalTo(161) |
| 133 | + } |
| 134 | + |
| 135 | + backButton.snp.makeConstraints { make in |
| 136 | + make.top.equalToSuperview().inset(14) |
| 137 | + make.leading.equalToSuperview().inset(6) |
| 138 | + make.width.height.equalTo(44) |
| 139 | + } |
| 140 | + |
| 141 | + messageImageView.snp.makeConstraints { make in |
| 142 | + make.top.equalToSuperview().inset(2) |
| 143 | + make.trailing.equalToSuperview().inset(16) |
| 144 | + } |
| 145 | + |
| 146 | + titleLabel.snp.makeConstraints { make in |
| 147 | + make.top.equalToSuperview().inset(72) |
| 148 | + make.leading.equalToSuperview().inset(20) |
| 149 | + } |
| 150 | + |
| 151 | + descriptionLabel.snp.makeConstraints { make in |
| 152 | + make.top.equalTo(titleLabel.snp.bottom).offset(4) |
| 153 | + make.leading.equalToSuperview().inset(20) |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + private func setEmptyViewContraint() { |
| 158 | + emptyView.snp.makeConstraints { make in |
| 159 | + make.top.equalTo(navigationView.snp.bottom).offset(0) |
| 160 | + make.leading.trailing.bottom.equalTo(view.safeAreaLayoutGuide).inset(0) |
| 161 | + } |
| 162 | + |
| 163 | + emptyMessageImageView.snp.makeConstraints { make in |
| 164 | + make.top.equalToSuperview().offset(constraintByNotch(83, 50)) |
| 165 | + make.centerX.equalToSuperview() |
| 166 | + } |
| 167 | + |
| 168 | + emptyDescriptionLabel.snp.makeConstraints { make in |
| 169 | + make.top.equalTo(emptyMessageImageView.snp.bottom).offset(8) |
| 170 | + make.centerX.equalToSuperview() |
| 171 | + } |
| 172 | + |
| 173 | + timeTravelButton.snp.makeConstraints { make in |
| 174 | + make.top.equalTo(emptyDescriptionLabel.snp.bottom).offset(12) |
| 175 | + make.width.equalTo(190) |
| 176 | + make.height.equalTo(68) |
| 177 | + make.centerX.equalToSuperview() |
| 178 | + } |
| 179 | + |
| 180 | + timeTravelView.snp.makeConstraints { make in |
| 181 | + make.top.leading.trailing.bottom.equalToSuperview() |
| 182 | + } |
| 183 | + } |
| 184 | +} |
0 commit comments