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 1/4] =?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) + } + } +} From 859572d2aeb0e020c5f582836a39dd59b18a6ad2 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:02:49 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[#142]=20=ED=95=84=EC=9A=94=EC=97=86?= =?UTF-8?q?=EB=8A=94=20=ED=8C=8C=EC=9D=BC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Deartoday/Deartoday.xcodeproj/project.pbxproj | 36 ------- .../CheckMessageDetail.storyboard | 97 ------------------- .../CheckMessageDetailViewController.swift | 63 ------------ .../View/CheckMessageDetailView.swift | 8 -- 4 files changed, 204 deletions(-) delete mode 100644 Deartoday/Deartoday/Screen/CheckMessageDetail/CheckMessageDetail.storyboard delete mode 100644 Deartoday/Deartoday/Screen/CheckMessageDetail/Controller/CheckMessageDetailViewController.swift delete mode 100644 Deartoday/Deartoday/Screen/CheckMessageDetail/View/CheckMessageDetailView.swift diff --git a/Deartoday/Deartoday.xcodeproj/project.pbxproj b/Deartoday/Deartoday.xcodeproj/project.pbxproj index 56d3d25..20877b7 100644 --- a/Deartoday/Deartoday.xcodeproj/project.pbxproj +++ b/Deartoday/Deartoday.xcodeproj/project.pbxproj @@ -98,9 +98,6 @@ 98A4750A287DECCF008891F5 /* CheckTimeTravel.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 98A47509287DECCF008891F5 /* CheckTimeTravel.storyboard */; }; 98A4750F287DECF7008891F5 /* CheckTImeTravelDataModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A4750E287DECF7008891F5 /* CheckTImeTravelDataModel.swift */; }; 98A47513287DED14008891F5 /* CheckTimeTravelViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A47512287DED14008891F5 /* CheckTimeTravelViewController.swift */; }; - 98A47516287E0106008891F5 /* CheckMessageDetail.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 98A47515287E0106008891F5 /* CheckMessageDetail.storyboard */; }; - 98A47519287E0129008891F5 /* CheckMessageDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A47518287E0129008891F5 /* CheckMessageDetailViewController.swift */; }; - 98A4751C287E013F008891F5 /* CheckMessageDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98A4751B287E013F008891F5 /* CheckMessageDetailView.swift */; }; 98A71D5A2882EEBA009508D9 /* Colors.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 98A71D592882EEBA009508D9 /* Colors.xcassets */; }; 98AD713928884FF700E910CD /* CheckMessageResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98AD713828884FF700E910CD /* CheckMessageResponse.swift */; }; 98B4B5AA287EB54600F4AD7A /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98B4B5A9287EB54600F4AD7A /* ViewController.swift */; }; @@ -222,9 +219,6 @@ 98A47509287DECCF008891F5 /* CheckTimeTravel.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = CheckTimeTravel.storyboard; sourceTree = ""; }; 98A4750E287DECF7008891F5 /* CheckTImeTravelDataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckTImeTravelDataModel.swift; sourceTree = ""; }; 98A47512287DED14008891F5 /* CheckTimeTravelViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckTimeTravelViewController.swift; sourceTree = ""; }; - 98A47515287E0106008891F5 /* CheckMessageDetail.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = CheckMessageDetail.storyboard; sourceTree = ""; }; - 98A47518287E0129008891F5 /* CheckMessageDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckMessageDetailViewController.swift; sourceTree = ""; }; - 98A4751B287E013F008891F5 /* CheckMessageDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckMessageDetailView.swift; sourceTree = ""; }; 98A71D592882EEBA009508D9 /* Colors.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Colors.xcassets; sourceTree = ""; }; 98AD713828884FF700E910CD /* CheckMessageResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckMessageResponse.swift; sourceTree = ""; }; 98B4B5A9287EB54600F4AD7A /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; @@ -552,7 +546,6 @@ 98245CDE28869980007821FA /* CheckTimeTravelDetail */, 4A2CEA6C2885A58A00DC9CC9 /* Splash */, 4ADAB7DA28846C9D0049C465 /* Initial */, - 98A47514287E00F1008891F5 /* CheckMessageDetail */, 924814A8287EB490001177B1 /* Dialog */, 98A47508287DECB6008891F5 /* CheckTimeTravel */, 98D912C6287DC2FF0088A7F9 /* CheckMessage */, @@ -918,32 +911,6 @@ path = Model; sourceTree = ""; }; - 98A47514287E00F1008891F5 /* CheckMessageDetail */ = { - isa = PBXGroup; - children = ( - 98A47515287E0106008891F5 /* CheckMessageDetail.storyboard */, - 98A4751A287E0136008891F5 /* View */, - 98A47517287E011F008891F5 /* Controller */, - ); - path = CheckMessageDetail; - sourceTree = ""; - }; - 98A47517287E011F008891F5 /* Controller */ = { - isa = PBXGroup; - children = ( - 98A47518287E0129008891F5 /* CheckMessageDetailViewController.swift */, - ); - path = Controller; - sourceTree = ""; - }; - 98A4751A287E0136008891F5 /* View */ = { - isa = PBXGroup; - children = ( - 98A4751B287E013F008891F5 /* CheckMessageDetailView.swift */, - ); - path = View; - sourceTree = ""; - }; 98A71D582882EEAC009508D9 /* Color */ = { isa = PBXGroup; children = ( @@ -1125,7 +1092,6 @@ 9803F3912882F3C300A5A239 /* timetape.json in Resources */, 98A71D5A2882EEBA009508D9 /* Colors.xcassets in Resources */, 986F5C4128883469001109F1 /* PresentDialogCollectionViewCell.xib in Resources */, - 98A47516287E0106008891F5 /* CheckMessageDetail.storyboard in Resources */, 98BFBCC22879B66A00F01F04 /* GmarketSansMedium.otf in Resources */, 92DB353A2875633F001E2006 /* Assets.xcassets in Resources */, 984099E92881F4A700025092 /* sound_box.mp3 in Resources */, @@ -1198,7 +1164,6 @@ 98D912C5287DB0130088A7F9 /* Lottie.swift in Sources */, 4ADAB7E9288507A10049C465 /* LoginResponse.swift in Sources */, 986E000328A62A04008EB3F2 /* MessageCollectionViewCell.swift in Sources */, - 98A47519287E0129008891F5 /* CheckMessageDetailViewController.swift in Sources */, 986F5C3C2888345E001109F1 /* PastDialogCollectionViewCell.swift in Sources */, 9803F3B428847C9100A5A239 /* MainResponse.swift in Sources */, 9803F3D82885953B00A5A239 /* CheckMessageService.swift in Sources */, @@ -1270,7 +1235,6 @@ 4A2CEA772885A91F00DC9CC9 /* SplashViewController.swift in Sources */, 98BFBCD12879BBB700F01F04 /* UIColor+.swift in Sources */, 4ADAB7E4288505A60049C465 /* LoginAPI.swift in Sources */, - 98A4751C287E013F008891F5 /* CheckMessageDetailView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Deartoday/Deartoday/Screen/CheckMessageDetail/CheckMessageDetail.storyboard b/Deartoday/Deartoday/Screen/CheckMessageDetail/CheckMessageDetail.storyboard deleted file mode 100644 index c93b69f..0000000 --- a/Deartoday/Deartoday/Screen/CheckMessageDetail/CheckMessageDetail.storyboard +++ /dev/null @@ -1,97 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Deartoday/Deartoday/Screen/CheckMessageDetail/Controller/CheckMessageDetailViewController.swift b/Deartoday/Deartoday/Screen/CheckMessageDetail/Controller/CheckMessageDetailViewController.swift deleted file mode 100644 index 6f1cf38..0000000 --- a/Deartoday/Deartoday/Screen/CheckMessageDetail/Controller/CheckMessageDetailViewController.swift +++ /dev/null @@ -1,63 +0,0 @@ -// -// CheckMessageDetailViewController.swift -// Deartoday -// -// Created by 이경민 on 2022/07/13. -// - -import UIKit - -final class CheckMessageDetailViewController: UIViewController { - - // MARK: - Property - - var content: String = "" - - // MARK: - UI Property - - @IBOutlet weak var messageView: UIView! - @IBOutlet weak var contentLabel: UILabel! - @IBOutlet weak var writerLabel: UILabel! - @IBOutlet weak var messageViewHeightConstraint: NSLayoutConstraint! - - // MARK: - Life Cycle - - override func viewDidLoad() { - super.viewDidLoad() - setData() - setUI() - } - - // MARK: - Custom Method - - private func setUI() { - setMessageViewUI() - setLabelUI() - setMessageViewDynamicHeight() - } - - private func setMessageViewUI() { - messageView.backgroundColor = .yellow03 - } - - private func setLabelUI() { - contentLabel.font = .p6 - writerLabel.font = .p6 - } - - private func setData() { - contentLabel.text = content - contentLabel.sizeToFit() - } - - private func setMessageViewDynamicHeight() { - messageViewHeightConstraint.constant = (contentLabel.frame.height < 145) - ? 200 : contentLabel.layer.frame.height + 80 - } - - // MARK: - IBAction - - @IBAction func closeButtonDidTap(_ sender: Any) { - dismiss(animated: false) - } -} diff --git a/Deartoday/Deartoday/Screen/CheckMessageDetail/View/CheckMessageDetailView.swift b/Deartoday/Deartoday/Screen/CheckMessageDetail/View/CheckMessageDetailView.swift deleted file mode 100644 index eec5e4d..0000000 --- a/Deartoday/Deartoday/Screen/CheckMessageDetail/View/CheckMessageDetailView.swift +++ /dev/null @@ -1,8 +0,0 @@ -// -// CheckMessageDetailView.swift -// Deartoday -// -// Created by 이경민 on 2022/07/13. -// - -import Foundation From 763294012d7545a875f8978880e4cf4b599412a1 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 17:18:16 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[#142]=20message=20view=20width=20=EC=9E=AC?= =?UTF-8?q?=EC=A1=B0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/MessageDetailViewController.swift | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Deartoday/Deartoday/Screen/CheckMessage/Controller/MessageDetailViewController.swift b/Deartoday/Deartoday/Screen/CheckMessage/Controller/MessageDetailViewController.swift index f2046f5..88206e4 100644 --- a/Deartoday/Deartoday/Screen/CheckMessage/Controller/MessageDetailViewController.swift +++ b/Deartoday/Deartoday/Screen/CheckMessage/Controller/MessageDetailViewController.swift @@ -14,7 +14,8 @@ final class MessageDetailViewController: UIViewController { // MARK: - Property - var content: String = "" + internal var content: String = "" + private let messageWidth = UIScreen.main.bounds.width - 175 // MARK: - UI Property @@ -69,11 +70,9 @@ final class MessageDetailViewController: UIViewController { } private func setDynamicHeight() { - let height = contentLabel.frame.height < 145 ? 200 : contentLabel.layer.frame.height + 80 - messageView.snp.remakeConstraints { make in - make.width.equalTo(200) + let height = contentLabel.frame.height < 145 ? messageWidth : contentLabel.layer.frame.height + 80 + messageView.snp.updateConstraints { make in make.height.equalTo(height) - make.centerX.centerY.equalTo(view.safeAreaLayoutGuide) } } @@ -84,8 +83,7 @@ final class MessageDetailViewController: UIViewController { private func setConstraint() { messageView.snp.makeConstraints { make in - make.width.equalTo(200) - make.height.equalTo(200) + make.width.height.equalTo(messageWidth) make.centerX.centerY.equalTo(view.safeAreaLayoutGuide) } From 5fef51fda152dc8d8b3d3dce29401c2ad0796383 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: Tue, 16 Aug 2022 01:18:09 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[#142]=20Message=20Detail=20=EB=B7=B0?= =?UTF-8?q?=EC=97=90=20Scroll=20view=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MessageDetailViewController.swift | 49 +++++++++++++++++-- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/Deartoday/Deartoday/Screen/CheckMessage/Controller/MessageDetailViewController.swift b/Deartoday/Deartoday/Screen/CheckMessage/Controller/MessageDetailViewController.swift index 88206e4..491c3df 100644 --- a/Deartoday/Deartoday/Screen/CheckMessage/Controller/MessageDetailViewController.swift +++ b/Deartoday/Deartoday/Screen/CheckMessage/Controller/MessageDetailViewController.swift @@ -23,10 +23,23 @@ final class MessageDetailViewController: UIViewController { $0.backgroundColor = .yellow03 } + private lazy var scrollView: UIScrollView = { + return UIScrollView(frame: .zero).then { + $0.backgroundColor = .clear + $0.bounces = false + $0.contentInsetAdjustmentBehavior = .never + } + }() + + private let contentView = UIView().then { + $0.backgroundColor = .clear + } + private lazy var contentLabel = UILabel().then { $0.font = .p6 $0.textColor = .black $0.numberOfLines = 0 + $0.lineBreakMode = .byCharWrapping $0.text = content $0.setTextWithLineHeight(text: content, lineHeight: 16.8) $0.sizeToFit() @@ -49,6 +62,10 @@ final class MessageDetailViewController: UIViewController { super.viewDidLoad() setUI() setLayout() + } + + override func viewWillLayoutSubviews() { + super.viewWillLayoutSubviews() setDynamicHeight() } @@ -70,15 +87,24 @@ final class MessageDetailViewController: UIViewController { } private func setDynamicHeight() { - let height = contentLabel.frame.height < 145 ? messageWidth : contentLabel.layer.frame.height + 80 + let maxHeight = getDeviceHeight() - 400 + let contentHeight = contentLabel.frame.height + 80 + let messageHeight = contentHeight < messageWidth ? messageWidth : + (contentHeight > maxHeight ? maxHeight : contentHeight) + messageView.snp.updateConstraints { make in - make.height.equalTo(height) + make.height.equalTo(messageHeight) + } + scrollView.snp.updateConstraints { make in + make.height.equalTo(messageHeight - 80) } } - + private func setHierarchy() { view.addSubviews([messageView, closeButton]) - messageView.addSubviews([contentLabel, writerLabel]) + messageView.addSubviews([scrollView, writerLabel]) + scrollView.addSubview(contentView) + contentView.addSubview(contentLabel) } private func setConstraint() { @@ -98,8 +124,21 @@ final class MessageDetailViewController: UIViewController { make.bottom.equalToSuperview().inset(13) } - contentLabel.snp.makeConstraints { make in + scrollView.snp.makeConstraints { make in make.top.leading.trailing.equalToSuperview().inset(20) + make.height.equalTo(messageWidth - 80) + } + + contentView.snp.makeConstraints { make in + make.top.leading.trailing.bottom.equalToSuperview().inset(0) + make.width.equalToSuperview() + make.height.equalToSuperview().priority(.low) + } + + contentLabel.snp.makeConstraints { make in + make.top.leading.equalToSuperview().inset(0) + make.trailing.equalTo(messageView.snp.trailing).inset(20) + make.bottom.equalToSuperview().inset(0) } } }