-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f30952
commit 134d425
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
Deartoday/Deartoday/Screen/CheckMessage/View/MessagesCollectionViewCell.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |