From 4599f23ba65650875afbe8e6e971c1a817376e91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EA=B2=BD=EB=AF=BC?= <74659491+meenyweeny@users.noreply.github.com> Date: Sat, 13 Aug 2022 16:01:55 +0900 Subject: [PATCH] =?UTF-8?q?[#142]=20message=20detail=20=EB=B7=B0=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=EB=A1=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Deartoday/Deartoday.xcodeproj/project.pbxproj | 4 + .../CheckMessageViewController.swift | 5 +- .../MessageDetailViewController.swift | 107 ++++++++++++++++++ 3 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 Deartoday/Deartoday/Screen/CheckMessage/Controller/MessageDetailViewController.swift diff --git a/Deartoday/Deartoday.xcodeproj/project.pbxproj b/Deartoday/Deartoday.xcodeproj/project.pbxproj index eb31d62..56d3d25 100644 --- a/Deartoday/Deartoday.xcodeproj/project.pbxproj +++ b/Deartoday/Deartoday.xcodeproj/project.pbxproj @@ -76,6 +76,7 @@ 9803F3D52885950F00A5A239 /* CheckMessageAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9803F3D42885950F00A5A239 /* CheckMessageAPI.swift */; }; 9803F3D82885953B00A5A239 /* CheckMessageService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9803F3D72885953B00A5A239 /* CheckMessageService.swift */; }; 9803F3E62885E0AD00A5A239 /* CheckTimeTravelDetailResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9803F3E52885E0AD00A5A239 /* CheckTimeTravelDetailResponse.swift */; }; + 981B059128A77AAF00394AE8 /* MessageDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 981B059028A77AAF00394AE8 /* MessageDetailViewController.swift */; }; 98245CE3288699A6007821FA /* CheckTimeTravelDetail.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 98245CE2288699A6007821FA /* CheckTimeTravelDetail.storyboard */; }; 98245CE728869A0A007821FA /* CheckTimeTravelDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98245CE628869A0A007821FA /* CheckTimeTravelDetailViewController.swift */; }; 98245CF028869CCB007821FA /* PastImageCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98245CEE28869CCB007821FA /* PastImageCollectionViewCell.swift */; }; @@ -199,6 +200,7 @@ 9803F3D42885950F00A5A239 /* CheckMessageAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckMessageAPI.swift; sourceTree = ""; }; 9803F3D72885953B00A5A239 /* CheckMessageService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckMessageService.swift; sourceTree = ""; }; 9803F3E52885E0AD00A5A239 /* CheckTimeTravelDetailResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckTimeTravelDetailResponse.swift; sourceTree = ""; }; + 981B059028A77AAF00394AE8 /* MessageDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageDetailViewController.swift; sourceTree = ""; }; 98245CE2288699A6007821FA /* CheckTimeTravelDetail.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = CheckTimeTravelDetail.storyboard; sourceTree = ""; }; 98245CE628869A0A007821FA /* CheckTimeTravelDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckTimeTravelDetailViewController.swift; sourceTree = ""; }; 98245CEE28869CCB007821FA /* PastImageCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PastImageCollectionViewCell.swift; sourceTree = ""; }; @@ -1012,6 +1014,7 @@ isa = PBXGroup; children = ( 986E000028A4DCC9008EB3F2 /* CheckMessageViewController.swift */, + 981B059028A77AAF00394AE8 /* MessageDetailViewController.swift */, ); path = Controller; sourceTree = ""; @@ -1185,6 +1188,7 @@ files = ( 92DB35682875656C001E2006 /* DDSButton.swift in Sources */, 923061D82877550E00F04EDA /* TimeTravelViewController.swift in Sources */, + 981B059128A77AAF00394AE8 /* MessageDetailViewController.swift in Sources */, 98D912AE287D558A0088A7F9 /* DeartodayModel.swift in Sources */, 923061D6287754FA00F04EDA /* TimeTravelView.swift in Sources */, 4A916177288921FD00F72BFC /* SettingViewController.swift in Sources */, diff --git a/Deartoday/Deartoday/Screen/CheckMessage/Controller/CheckMessageViewController.swift b/Deartoday/Deartoday/Screen/CheckMessage/Controller/CheckMessageViewController.swift index 883cb11..092fcc7 100644 --- a/Deartoday/Deartoday/Screen/CheckMessage/Controller/CheckMessageViewController.swift +++ b/Deartoday/Deartoday/Screen/CheckMessage/Controller/CheckMessageViewController.swift @@ -202,11 +202,10 @@ final class CheckMessageViewController: UIViewController { extension CheckMessageViewController: UICollectionViewDelegate { func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { - guard let messageDetail = UIStoryboard(name: Constant.Storyboard.CheckMessageDetail, bundle: nil) - .instantiateViewController(withIdentifier: Constant.ViewController.CheckMessageDetail) as? CheckMessageDetailViewController else { return } + let messageDetail = MessageDetailViewController() messageDetail.modalPresentationStyle = .overFullScreen messageDetail.content = messages[indexPath.item].message - present(messageDetail, animated: false, completion: nil) + present(messageDetail, animated: false) } } diff --git a/Deartoday/Deartoday/Screen/CheckMessage/Controller/MessageDetailViewController.swift b/Deartoday/Deartoday/Screen/CheckMessage/Controller/MessageDetailViewController.swift new file mode 100644 index 0000000..f2046f5 --- /dev/null +++ b/Deartoday/Deartoday/Screen/CheckMessage/Controller/MessageDetailViewController.swift @@ -0,0 +1,107 @@ +// +// MessageDetailViewController.swift +// Deartoday +// +// Created by 이경민 on 2022/08/13. +// + +import UIKit + +import SnapKit +import Then + +final class MessageDetailViewController: UIViewController { + + // MARK: - Property + + var content: String = "" + + // MARK: - UI Property + + private let messageView = UIView().then { + $0.backgroundColor = .yellow03 + } + + private lazy var contentLabel = UILabel().then { + $0.font = .p6 + $0.textColor = .black + $0.numberOfLines = 0 + $0.text = content + $0.setTextWithLineHeight(text: content, lineHeight: 16.8) + $0.sizeToFit() + } + + private let writerLabel = UILabel().then { + $0.font = .p6 + $0.textColor = .black + $0.text = "From. 미래의 나" + } + + private let closeButton = UIButton().then { + $0.setImage(Constant.Image.icClose, for: .normal) + $0.addTarget(self, action: #selector(closeButtonDidTap), for: .touchUpInside) + } + + // MARK: - Life Cycle + + override func viewDidLoad() { + super.viewDidLoad() + setUI() + setLayout() + setDynamicHeight() + } + + // MARK: - @objc + + @objc private func closeButtonDidTap() { + dismiss(animated: false) + } + + // MARK: - Custom Method + + private func setUI() { + view.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.7) + } + + private func setLayout() { + setHierarchy() + setConstraint() + } + + private func setDynamicHeight() { + let height = contentLabel.frame.height < 145 ? 200 : contentLabel.layer.frame.height + 80 + messageView.snp.remakeConstraints { make in + make.width.equalTo(200) + make.height.equalTo(height) + make.centerX.centerY.equalTo(view.safeAreaLayoutGuide) + } + } + + private func setHierarchy() { + view.addSubviews([messageView, closeButton]) + messageView.addSubviews([contentLabel, writerLabel]) + } + + private func setConstraint() { + messageView.snp.makeConstraints { make in + make.width.equalTo(200) + make.height.equalTo(200) + make.centerX.centerY.equalTo(view.safeAreaLayoutGuide) + } + + closeButton.snp.makeConstraints { make in + make.top.equalTo(messageView.snp.bottom).offset(8) + make.width.height.equalTo(44) + make.centerX.equalTo(messageView) + } + + writerLabel.snp.makeConstraints { make in + make.leading.equalToSuperview().inset(20) + make.bottom.equalToSuperview().inset(13) + } + + contentLabel.snp.makeConstraints { make in + make.top.leading.trailing.equalToSuperview().inset(20) + } + } +}