Skip to content

Commit

Permalink
[#142] message detail 뷰 코드로 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
meenyweeny committed Aug 13, 2022
1 parent 06b9db2 commit 4599f23
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Deartoday/Deartoday.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -199,6 +200,7 @@
9803F3D42885950F00A5A239 /* CheckMessageAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckMessageAPI.swift; sourceTree = "<group>"; };
9803F3D72885953B00A5A239 /* CheckMessageService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckMessageService.swift; sourceTree = "<group>"; };
9803F3E52885E0AD00A5A239 /* CheckTimeTravelDetailResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckTimeTravelDetailResponse.swift; sourceTree = "<group>"; };
981B059028A77AAF00394AE8 /* MessageDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageDetailViewController.swift; sourceTree = "<group>"; };
98245CE2288699A6007821FA /* CheckTimeTravelDetail.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = CheckTimeTravelDetail.storyboard; sourceTree = "<group>"; };
98245CE628869A0A007821FA /* CheckTimeTravelDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckTimeTravelDetailViewController.swift; sourceTree = "<group>"; };
98245CEE28869CCB007821FA /* PastImageCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PastImageCollectionViewCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1012,6 +1014,7 @@
isa = PBXGroup;
children = (
986E000028A4DCC9008EB3F2 /* CheckMessageViewController.swift */,
981B059028A77AAF00394AE8 /* MessageDetailViewController.swift */,
);
path = Controller;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

0 comments on commit 4599f23

Please sign in to comment.