Skip to content

Commit

Permalink
[#142] Message cell UI 코드로 다시 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
meenyweeny committed Aug 12, 2022
1 parent 8f30952 commit 134d425
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Deartoday/Deartoday.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
9858B3D0288097B000860439 /* MessageCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9858B3CE288097B000860439 /* MessageCollectionViewCell.swift */; };
9858B3D1288097B000860439 /* MessageCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9858B3CF288097B000860439 /* MessageCollectionViewCell.xib */; };
986E000128A4DCC9008EB3F2 /* CheckMessagesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 986E000028A4DCC9008EB3F2 /* CheckMessagesViewController.swift */; };
986E000328A62A04008EB3F2 /* MessagesCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 986E000228A62A04008EB3F2 /* MessagesCollectionViewCell.swift */; };
986F5C362887FA83001109F1 /* TravelInfoCollectionReusableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 986F5C342887FA83001109F1 /* TravelInfoCollectionReusableView.swift */; };
986F5C372887FA83001109F1 /* TravelInfoCollectionReusableView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 986F5C352887FA83001109F1 /* TravelInfoCollectionReusableView.xib */; };
986F5C3C2888345E001109F1 /* PastDialogCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 986F5C3A2888345E001109F1 /* PastDialogCollectionViewCell.swift */; };
Expand Down Expand Up @@ -214,6 +215,7 @@
9858B3CE288097B000860439 /* MessageCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageCollectionViewCell.swift; sourceTree = "<group>"; };
9858B3CF288097B000860439 /* MessageCollectionViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MessageCollectionViewCell.xib; sourceTree = "<group>"; };
986E000028A4DCC9008EB3F2 /* CheckMessagesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckMessagesViewController.swift; sourceTree = "<group>"; };
986E000228A62A04008EB3F2 /* MessagesCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessagesCollectionViewCell.swift; sourceTree = "<group>"; };
986F5C342887FA83001109F1 /* TravelInfoCollectionReusableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TravelInfoCollectionReusableView.swift; sourceTree = "<group>"; };
986F5C352887FA83001109F1 /* TravelInfoCollectionReusableView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = TravelInfoCollectionReusableView.xib; sourceTree = "<group>"; };
986F5C3A2888345E001109F1 /* PastDialogCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PastDialogCollectionViewCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1026,6 +1028,7 @@
children = (
9858B3CE288097B000860439 /* MessageCollectionViewCell.swift */,
9858B3CF288097B000860439 /* MessageCollectionViewCell.xib */,
986E000228A62A04008EB3F2 /* MessagesCollectionViewCell.swift */,
);
path = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -1200,6 +1203,7 @@
9803F3BD2884814C00A5A239 /* MainAPI.swift in Sources */,
98D912C5287DB0130088A7F9 /* Lottie.swift in Sources */,
4ADAB7E9288507A10049C465 /* LoginResponse.swift in Sources */,
986E000328A62A04008EB3F2 /* MessagesCollectionViewCell.swift in Sources */,
98A47519287E0129008891F5 /* CheckMessageDetailViewController.swift in Sources */,
986F5C3C2888345E001109F1 /* PastDialogCollectionViewCell.swift in Sources */,
9803F3B428847C9100A5A239 /* MainResponse.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//
// MessagesCollectionViewCell.swift
// Deartoday
//
// Created by 이경민 on 2022/08/12.
//

import UIKit

import SnapKit
import Then

final class MessagesCollectionViewCell: UICollectionViewCell {

static let identifier = "MessagesCollectionViewCell"

// MARK: - UI Property

private let contentLabel = UILabel().then {
$0.font = .p6
$0.textColor = .black
$0.numberOfLines = 0
}

private let writerLabel = UILabel().then {
$0.font = .p6
$0.textColor = .black
$0.text = "From. 미래의 나"
}

// MARK: - Life Cycle

override init(frame: CGRect) {
super.init(frame: frame)
setUI()
setLayout()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

// MARK: - Custom Method

private func setUI() {
backgroundColor = .yellow03
}

private func setLayout() {
setHierarchy()
setConstraint()
}

private func setHierarchy() {
addSubviews([contentLabel, writerLabel])
}

private func setConstraint() {
contentLabel.snp.makeConstraints { make in
make.top.leading.trailing.equalToSuperview().inset(16)
}

writerLabel.snp.makeConstraints { make in
make.leading.equalToSuperview().inset(16)
make.bottom.equalToSuperview().inset(7)
}
}

private func adjustContentSize() {
contentLabel.setTextWithLineHeight(text: contentLabel.text, lineHeight: 16.8)
contentLabel.sizeToFit()
let labelHeight = (((UIScreen.main.bounds.width - 55)/2)-59)
let isLongContent = (contentLabel.frame.height > labelHeight)
contentLabel.lineBreakMode = isLongContent ? .byTruncatingTail : .byCharWrapping
contentLabel.snp.remakeConstraints { make in
make.top.leading.trailing.equalToSuperview().inset(16)
make.height.equalTo(isLongContent ? labelHeight : contentLabel.frame.height)
}
}

func setData(content: String) {
contentLabel.text = content
adjustContentSize()
}
}

0 comments on commit 134d425

Please sign in to comment.