Skip to content

Commit

Permalink
[refactor] NewNoteDatePickerViewController UI 요소들 코드로 변환 #302
Browse files Browse the repository at this point in the history
  • Loading branch information
skkimeo committed Jul 1, 2023
1 parent 5d80248 commit 124f5eb
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 98 deletions.
8 changes: 4 additions & 4 deletions Happiggy-bank/Happiggy-bank.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
A466A31A2802987700D655F4 /* UIAlertAction+ConfirmAndCancel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A466A3192802987700D655F4 /* UIAlertAction+ConfirmAndCancel.swift */; };
A466A31C28029D7400D655F4 /* UIAlertController+BasicFormat.swift in Sources */ = {isa = PBXBuildFile; fileRef = A466A31B28029D7400D655F4 /* UIAlertController+BasicFormat.swift */; };
A467B5C827DA258700AC702D /* NewNoteDatePickerRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A467B5C727DA258700AC702D /* NewNoteDatePickerRowView.swift */; };
A467B5CA27DA289600AC702D /* NewNoteDatePickerRowView.xib in Resources */ = {isa = PBXBuildFile; fileRef = A467B5C927DA289500AC702D /* NewNoteDatePickerRowView.xib */; };
A46B10EC2813E73F004AB185 /* UserDefaults+Keys.swift in Sources */ = {isa = PBXBuildFile; fileRef = A46B10EB2813E73F004AB185 /* UserDefaults+Keys.swift */; };
A46B10F028142DB1004AB185 /* UIFont+Weight.swift in Sources */ = {isa = PBXBuildFile; fileRef = A46B10EF28142DB1004AB185 /* UIFont+Weight.swift */; };
A46B10F228142F26004AB185 /* UIViewController+ObserveCustomFontChange.swift in Sources */ = {isa = PBXBuildFile; fileRef = A46B10F128142F26004AB185 /* UIViewController+ObserveCustomFontChange.swift */; };
Expand All @@ -69,6 +68,7 @@
A472C5F729C2DDFF00097432 /* NewNoteInputViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A472C5F629C2DDFF00097432 /* NewNoteInputViewModel.swift */; };
A472C5F929C2ED5000097432 /* HBError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A472C5F829C2ED5000097432 /* HBError.swift */; };
A472C5FB29C2F21600097432 /* NewNoteSavingDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A472C5FA29C2F21600097432 /* NewNoteSavingDelegate.swift */; };
A472C60329C408D000097432 /* NewNoteDatePickingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A472C60229C408D000097432 /* NewNoteDatePickingView.swift */; };
A47D83462966C0C60028AA1D /* NotificationSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D22ADF7E27F72F7300ECB77B /* NotificationSettingsViewModel.swift */; };
A47D83482966D3870028AA1D /* FontSelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A47D83472966D3870028AA1D /* FontSelectionView.swift */; };
A47D834A296716BF0028AA1D /* FontCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A47D8349296716BF0028AA1D /* FontCell.swift */; };
Expand Down Expand Up @@ -226,7 +226,6 @@
A466A3192802987700D655F4 /* UIAlertAction+ConfirmAndCancel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIAlertAction+ConfirmAndCancel.swift"; sourceTree = "<group>"; };
A466A31B28029D7400D655F4 /* UIAlertController+BasicFormat.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIAlertController+BasicFormat.swift"; sourceTree = "<group>"; };
A467B5C727DA258700AC702D /* NewNoteDatePickerRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewNoteDatePickerRowView.swift; sourceTree = "<group>"; };
A467B5C927DA289500AC702D /* NewNoteDatePickerRowView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NewNoteDatePickerRowView.xib; sourceTree = "<group>"; };
A46B10EB2813E73F004AB185 /* UserDefaults+Keys.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UserDefaults+Keys.swift"; sourceTree = "<group>"; };
A46B10EF28142DB1004AB185 /* UIFont+Weight.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIFont+Weight.swift"; sourceTree = "<group>"; };
A46B10F128142F26004AB185 /* UIViewController+ObserveCustomFontChange.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+ObserveCustomFontChange.swift"; sourceTree = "<group>"; };
Expand All @@ -252,6 +251,7 @@
A472C5F629C2DDFF00097432 /* NewNoteInputViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewNoteInputViewModel.swift; sourceTree = "<group>"; };
A472C5F829C2ED5000097432 /* HBError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HBError.swift; sourceTree = "<group>"; };
A472C5FA29C2F21600097432 /* NewNoteSavingDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewNoteSavingDelegate.swift; sourceTree = "<group>"; };
A472C60229C408D000097432 /* NewNoteDatePickingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewNoteDatePickingView.swift; sourceTree = "<group>"; };
A47D83472966D3870028AA1D /* FontSelectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FontSelectionView.swift; sourceTree = "<group>"; };
A47D8349296716BF0028AA1D /* FontCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FontCell.swift; sourceTree = "<group>"; };
A47D83532973A4860028AA1D /* FontPublishing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FontPublishing.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -823,13 +823,13 @@
A896FBEF2966B5DE00A3400B /* View */ = {
isa = PBXGroup;
children = (
A467B5C927DA289500AC702D /* NewNoteDatePickerRowView.xib */,
A4A55A0828FFC675004ABE00 /* NewNoteInputView.swift */,
A467B5C727DA258700AC702D /* NewNoteDatePickerRowView.swift */,
A4CF2C7F27C733FE001B01B1 /* ColorButton.swift */,
A4EDFE802902D72A0056C2DC /* ColorPickerBarItem.swift */,
A4845B5C2900DF0B00A6007C /* ColorPicker.swift */,
A472C5F429C2DCEA00097432 /* NewNoteInputToolbar.swift */,
A472C60229C408D000097432 /* NewNoteDatePickingView.swift */,
);
path = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -1331,7 +1331,6 @@
A49B25F12812BF6800399630 /* dovemayo_bold.otf in Resources */,
A46B110D2814617B004AB185 /* IBMPlexSansKR-Regular.otf in Resources */,
A8FC07DD27B3EF030077A758 /* .swiftlint.yml in Resources */,
A467B5CA27DA289600AC702D /* NewNoteDatePickerRowView.xib in Resources */,
A46B111128146188004AB185 /* Cafe24SsurroundAir.ttf in Resources */,
A8FC07D427B3ECF30077A758 /* LaunchScreen.storyboard in Resources */,
A49B25F22812BF6B00399630 /* dovemayo.otf in Resources */,
Expand Down Expand Up @@ -1396,6 +1395,7 @@
A499318327BF5158009FF5A8 /* BottleNoteView.swift in Sources */,
A4CF2C8E27CBA49D001B01B1 /* UIViewController+NotificationCenter.swift in Sources */,
A46BC1EF2800626A00C2E5B4 /* TabItem.swift in Sources */,
A472C60329C408D000097432 /* NewNoteDatePickingView.swift in Sources */,
A4569CBE28105052001E3FD6 /* CustomerServiceViewModel.swift in Sources */,
A8F985E0296FDE6000E5ACC6 /* ListTabViewController.swift in Sources */,
D284A5DE27FF3EFB00D20699 /* BottleNameEditViewController.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ extension NewNoteDatePickerViewController: UIPickerViewDelegate {

/// 데이터에 맞게 행의 모습(날짜 라벨 텍스트와 쪽지 이미지 색깔) 업데이트
rowView.dateLabel.attributedText = self.viewModel.attributedDateString(for: noteData)
rowView.colorImageView.image = self.viewModel.image(for: noteData)
rowView.noteImageView.image = self.viewModel.image(for: noteData)

return rowView
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,70 @@
import UIKit

/// 새로운 쪽지 추가 시 사용하는 날짜 피커의 각 행을 나타내는 뷰
class NewNoteDatePickerRowView: UIView {

// MARK: - @IBOutlet

/// 이미지 뷰와 날짜 라벨을 담고 있는 스택 뷰 DatePickerRowView.xib 과 연결
@IBOutlet var contentView: UIStackView!

final class NewNoteDatePickerRowView: UIView {

// MARK: - Properties

/// 해당 날짜에 쪽지를 썼는지 나타낼 이미지 뷰
@IBOutlet var colorImageView: UIImageView!

/// 날짜 라벨
@IBOutlet var dateLabel: UILabel!


// MARK: - Init
let noteImageView = UIImageView().then {
$0.clipsToBounds = true
$0.isUserInteractionEnabled = true
$0.contentMode = .scaleAspectFit
}

let dateLabel = BaseLabel().then {
$0.changeFontSize(to: FontSize.body1)
}

private let contentStack = UIStackView().then {
$0.spacing = Metric.spacing11
}


// MARK: - Init(s)

override init(frame: CGRect) {
super.init(frame: frame)
self.commonInit()


self.configureViews()
}

required init?(coder: NSCoder) {
super.init(coder: coder)
self.commonInit()

self.configureViews()
}


// MARK: - Functions

/// contentview 를 하위 뷰로 추가하고, frame, autoresizingMask 설정
private func commonInit() {
Bundle.main.loadNibNamed(NewNoteDatePickerRowView.name, owner: self, options: nil)
self.addSubview(self.contentView)
self.contentView.frame = self.bounds
self.contentView.autoresizingMask = [.flexibleWidth, .flexibleHeight]


// MARK: - Configuration Functions

private func configureViews() {
self.configureSubviews()
self.configureConstraints()
}

private func configureSubviews() {
self.addSubview(self.contentStack)
self.contentStack.addArrangedSubviews(self.noteImageView, self.dateLabel)
}

private func configureConstraints() {
self.contentStack.snp.makeConstraints {
$0.verticalEdges.equalToSuperview().inset(Metric.spacing4)
}
self.dateLabel.snp.makeConstraints { $0.centerX.equalTo(self) }
self.noteImageView.snp.makeConstraints {
$0.width.equalTo(self.noteImageView.snp.height).multipliedBy(CGFloat.one)
}
}
}


// MARK: - Constants
fileprivate extension NewNoteDatePickerRowView {

enum Metric {
static let spacing4: CGFloat = 4
static let spacing11: CGFloat = 11
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
//
// NewNoteDatePickingView.swift
// Happiggy-bank
//
// Created by sun on 2023/03/17.
//

import UIKit

final class NewNoteDatePickingView: UIView {

// MARK: - Properties

let datePicker = UIPickerView()

let warningLabel = BaseLabel().then {
$0.text = StringLiteral.warning
$0.textColor = AssetColor.etcAlert
$0.changeFontSize(to: FontSize.body4)
$0.isHidden = true
}

private let instructionLabel = BaseLabel().then {
$0.text = StringLiteral.instruction
$0.textColor = AssetColor.mainYellow
$0.changeFontSize(to: FontSize.body2)
}


// MARK: - Init(s)

override init(frame: CGRect) {
super.init(frame: frame)

self.configureViews()
}

required init?(coder: NSCoder) {
super.init(coder: coder)

self.configureViews()
}


// MARK: - Configuration Functions

private func configureViews() {
self.configureSubviews()
self.configureConstraints()
}

private func configureSubviews() {
self.addSubviews(self.instructionLabel, self.datePicker, self.warningLabel)
self.configureSelectionIndicator()
}

/// 날짜 피커의 셀렉션 인디케이터를 흰색으로 변경
private func configureSelectionIndicator() {
self.datePicker.layoutIfNeeded()
/// 기존 인디케이터 투명 처리
guard let formerSelectionIndicator = self.datePicker.subviews[safe: 1]
else {
return
}

formerSelectionIndicator.backgroundColor = .clear

/// 흰색의 새로운 인디케이터 생성
let newSelectionIndictor = UIView().then {
$0.frame = formerSelectionIndicator.frame
$0.layer.cornerRadius = formerSelectionIndicator.layer.cornerRadius
$0.backgroundColor = .systemBackground
}

/// 뷰 체계에 삽입 및 오토 레이아웃 설정
self.insertSubview(newSelectionIndictor, belowSubview: self.datePicker)
newSelectionIndictor.snp.makeConstraints {
$0.center.size.equalTo(formerSelectionIndicator)
}
}

private func configureConstraints() {
self.datePicker.snp.makeConstraints { $0.center.equalToSuperview() }
self.instructionLabel.snp.makeConstraints {
$0.centerX.equalTo(self.datePicker)
$0.bottom.equalTo(self.datePicker.snp.top).offset(-Metric.spacing45)
}
self.warningLabel.snp.makeConstraints {
$0.centerX.equalTo(self.datePicker)
$0.top.equalTo(self.datePicker.snp.bottom).offset(Metric.spacing45)
}
}
}


// MARK: - Constants
fileprivate extension NewNoteDatePickingView {

enum Metric {
static let spacing45: CGFloat = 45
}

enum StringLiteral {
static let instruction = "작성 날짜를 선택해 주세요"
static let warning = "해당 날짜에는 이미 쪽지를 작성했어요!"
}
}

0 comments on commit 124f5eb

Please sign in to comment.