Skip to content

Commit

Permalink
[Feat] Wal Creator 코드정리 및 count UI 구현 (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
pcsoyeon committed Sep 10, 2023
1 parent f2b0ce6 commit eb864a1
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 21 deletions.
11 changes: 10 additions & 1 deletion WAL/WAL.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
"version" : "3.3.1"
}
},
{
"identity" : "lottie-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/airbnb/lottie-ios.git",
"state" : {
"revision" : "d6feea26a370019b4d3a85f5984cb95a2734776f",
"version" : "4.2.0"
}
},
{
"identity" : "snapkit",
"kind" : "remoteSourceControl",
Expand All @@ -24,7 +33,7 @@
"location" : "https://github.com/zanzanbari/WALKit.git",
"state" : {
"branch" : "develop",
"revision" : "31eaa8614c9e330f7e0c54d54e95aed1fc66e536"
"revision" : "c976c62e4986561c2eac9080cabfa3aee9dd7f97"
}
}
],
Expand Down
89 changes: 69 additions & 20 deletions WAL/WAL/Screen/Setting/Controller/WalCreatorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ final class WalCreatorViewController: UIViewController {
}

private lazy var guideImageView = UIImageView().then {
$0.backgroundColor = .mint100
$0.image = WALIcon.icnCreate.image
$0.contentMode = .scaleToFill
}

private lazy var guideTitleLabel = UILabel().then {
Expand Down Expand Up @@ -97,26 +98,35 @@ final class WalCreatorViewController: UIViewController {
$0.layer.borderWidth = 1
$0.layer.cornerRadius = 10
$0.delegate = self
$0.tintColor = .orange100
}

private let placeholderLabel = UILabel().then {
private lazy var placeholderLabel = UILabel().then {
$0.textColor = .gray300
$0.font = WALFont.body5.font
$0.text = "내가 받을 왈소리를 작성해주세요"
}

private let countLabel = UILabel().then {
private lazy var countLabel = UILabel().then {
$0.textColor = .gray200
$0.font = WALFont.body8.font
$0.text = "0"
}

private let maximumCountLabel = UILabel().then {
private lazy var maximumCountLabel = UILabel().then {
$0.textColor = .gray200
$0.font = WALFont.body8.font
$0.text = "/50"
}

private lazy var countStackView = UIStackView().then {
$0.axis = .horizontal
$0.alignment = .fill
$0.distribution = .fill
$0.spacing = 0
$0.addArrangedSubviews([countLabel, maximumCountLabel])
}

private lazy var sendButton = WALPlainButton().then {
$0.title = "보내기"
$0.isDisabled = true
Expand All @@ -128,9 +138,15 @@ final class WalCreatorViewController: UIViewController {
$0.alpha = 0
}

private lazy var walTypePickerView = UIPickerView().then {
$0.delegate = self
$0.dataSource = self
$0.autoresizingMask = .flexibleWidth
$0.backgroundColor = .gray500
}

// MARK: - Property

private lazy var walTypePickerView = UIPickerView()
private var walType: [WalCategoryType] = [.comedy, .fuss, .comfort, .yell]

// MARK: - Initializer
Expand All @@ -151,7 +167,6 @@ final class WalCreatorViewController: UIViewController {
super.viewDidLoad()
configUI()
setupLayout()
setPickerView()
setTextField()
setToolbar()
}
Expand All @@ -173,7 +188,12 @@ final class WalCreatorViewController: UIViewController {
}

private func setupLayout() {
view.addSubviews([guideBackView, navigationBackView, navigationBar, walInputBackView, sendButton])
view.addSubviews([guideBackView,
navigationBackView,
navigationBar,
walInputBackView,
sendButton])

guideBackView.snp.makeConstraints {
$0.bottom.equalTo(walInputBackView.snp.top)
$0.horizontalEdges.equalToSuperview()
Expand Down Expand Up @@ -212,10 +232,11 @@ final class WalCreatorViewController: UIViewController {
guideBackView.addSubviews([guideImageView,
guideTitleLabel,
guideSubtitleLabel])

guideImageView.snp.makeConstraints {
$0.top.equalToSuperview().inset(110)
$0.width.equalTo(132)
$0.height.equalTo(121)
$0.width.equalTo(188)
$0.height.equalTo(122)
$0.centerX.equalToSuperview()
}

Expand All @@ -226,13 +247,18 @@ final class WalCreatorViewController: UIViewController {

guideSubtitleLabel.snp.makeConstraints {
$0.top.equalTo(guideTitleLabel.snp.bottom).offset(11)
$0.horizontalEdges.equalToSuperview().inset(20)
$0.horizontalEdges.equalToSuperview().inset(Layouts.horizontalMargin)
}
}

/// 왈소리 유형/컨텐츠 입력 UI Layout
private func setupInputViewLayout() {
walInputBackView.addSubviews([walTypeTitleLabel, walTypeTextField, walTextTitleLabel, walTextView])
walInputBackView.addSubviews([walTypeTitleLabel,
walTypeTextField,
walTextTitleLabel,
walTextView,
countStackView])

walTypeTitleLabel.snp.makeConstraints {
$0.top.equalToSuperview().offset(26)
$0.leading.equalToSuperview().inset(Layouts.horizontalMargin)
Expand All @@ -250,6 +276,10 @@ final class WalCreatorViewController: UIViewController {
$0.horizontalEdges.equalToSuperview().inset(Layouts.horizontalMargin)
$0.height.equalTo(99)
}
countStackView.snp.makeConstraints {
$0.bottom.equalTo(walTextView.snp.bottom).inset(10)
$0.trailing.equalTo(walTextView.snp.trailing).inset(17)
}
}

// MARK: - Custom Method
Expand All @@ -270,11 +300,6 @@ final class WalCreatorViewController: UIViewController {
sendButton.isEnabled = isCotentFull
}

private func setPickerView() {
walTypePickerView.delegate = self
walTypePickerView.dataSource = self
}

private func setTextField() {
walTypeTextField.delegate = self

Expand Down Expand Up @@ -344,6 +369,7 @@ final class WalCreatorViewController: UIViewController {
extension WalCreatorViewController {

enum Layouts {
/// 좌/우
static let horizontalMargin = 20
}

Expand Down Expand Up @@ -382,9 +408,9 @@ extension WalCreatorViewController: UITextViewDelegate {
func textViewDidChange(_ textView: UITextView) {
countLabel.text = "\(walTextView.text.count)"

countLabel.textColor = walTextView.text.count >= 100 ? .orange100 : .gray200
countLabel.textColor = walTextView.text.count >= 50 ? .orange100 : .gray200

if walTextView.text.count > 100 {
if walTextView.text.count > 50 {
walTextView.deleteBackward()
}

Expand Down Expand Up @@ -413,12 +439,35 @@ extension WalCreatorViewController: UIPickerViewDelegate, UIPickerViewDataSource
return walType.count
}

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return walType[row].kor
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
let label = (view as? UILabel) ?? UILabel()

label.textAlignment = .center

if pickerView.selectedRow(inComponent: component) == row {
label.attributedText = NSAttributedString(string: walType[row].kor,
attributes: [NSAttributedString.Key.font: WALFont.body2.font,
NSAttributedString.Key.foregroundColor: UIColor.orange100])
} else {
label.attributedText = NSAttributedString(string: walType[row].kor,
attributes: [NSAttributedString.Key.font: WALFont.body2.font,
NSAttributedString.Key.foregroundColor: UIColor.gray100])
}

return label
}

func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
return 44
}

func pickerView(_ pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat {
return 200
}

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
walTypeTextField.text = walType[row].kor
pickerView.reloadAllComponents()
}

}

0 comments on commit eb864a1

Please sign in to comment.