Skip to content

Commit

Permalink
[FEAT] TeamNADA#88 - 명함생성뷰에서 피커뷰로 생년월일, mbti 설정
Browse files Browse the repository at this point in the history
### Descriptions
- Notification Center 을 활용해서 바텀시트에서 데이터 전달
- SelectBirthBottomViewController: 생년월일 커스텀 바텀시트 뷰
- SelectMBTIBottomViewController: MBTI 커스텀 바텀시트 뷰
  • Loading branch information
hyun99999 committed Dec 1, 2021
1 parent a155ca8 commit de3d09a
Show file tree
Hide file tree
Showing 9 changed files with 399 additions and 14 deletions.
20 changes: 18 additions & 2 deletions NADA-iOS-forRelease.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
F87122762733046300A24E74 /* Card.swift in Sources */ = {isa = PBXBuildFile; fileRef = F87122752733046300A24E74 /* Card.swift */; };
F871227827330A3800A24E74 /* CardCreationRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = F871227727330A3800A24E74 /* CardCreationRequest.swift */; };
F8719DDB274F92E90081AD51 /* UITextField+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8719DDA274F92E90081AD51 /* UITextField+Extension.swift */; };
F8915A22275728F20013D609 /* SelectBirthBottomViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8915A20275728F20013D609 /* SelectBirthBottomViewController.swift */; };
F8915A23275728F20013D609 /* SelectMBTIBottomViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8915A21275728F20013D609 /* SelectMBTIBottomViewController.swift */; };
F8A9FE1A2743DC6B00BC60CE /* CardListInGroupRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8A9FE192743DC6B00BC60CE /* CardListInGroupRequest.swift */; };
F8C310C0273A7360008EC5BA /* FrontCardCreationDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8C310BF273A7360008EC5BA /* FrontCardCreationDelegate.swift */; };
F8C83FAE272F99940009DF0D /* MoyaLoggerPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8C83FAD272F99940009DF0D /* MoyaLoggerPlugin.swift */; };
Expand Down Expand Up @@ -195,6 +197,8 @@
F87122752733046300A24E74 /* Card.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Card.swift; sourceTree = "<group>"; };
F871227727330A3800A24E74 /* CardCreationRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardCreationRequest.swift; sourceTree = "<group>"; };
F8719DDA274F92E90081AD51 /* UITextField+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITextField+Extension.swift"; sourceTree = "<group>"; };
F8915A20275728F20013D609 /* SelectBirthBottomViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelectBirthBottomViewController.swift; sourceTree = "<group>"; };
F8915A21275728F20013D609 /* SelectMBTIBottomViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelectMBTIBottomViewController.swift; sourceTree = "<group>"; };
F8A9FE192743DC6B00BC60CE /* CardListInGroupRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardListInGroupRequest.swift; sourceTree = "<group>"; };
F8C310BF273A7360008EC5BA /* FrontCardCreationDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FrontCardCreationDelegate.swift; sourceTree = "<group>"; };
F8C83FAD272F99940009DF0D /* MoyaLoggerPlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoyaLoggerPlugin.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -380,6 +384,8 @@
398413B6274A7A1E005550BC /* AddGroupBottomSheetViewController.swift */,
77703156275005AA002CBD19 /* CardResultBottomSheetViewController.swift */,
7713E8472752E2A900724C8B /* SelectGroupBottomSheetViewController.swift */,
F8915A20275728F20013D609 /* SelectBirthBottomViewController.swift */,
F8915A21275728F20013D609 /* SelectMBTIBottomViewController.swift */,
);
path = BottomSheet;
sourceTree = "<group>";
Expand Down Expand Up @@ -518,6 +524,15 @@
path = Card;
sourceTree = "<group>";
};
F8915A1F275713A10013D609 /* CardCreation */ = {
isa = PBXGroup;
children = (
F8FC43B226C020B90033E151 /* BackCardCreationDelegate.swift */,
F8C310BF273A7360008EC5BA /* FrontCardCreationDelegate.swift */,
);
path = CardCreation;
sourceTree = "<group>";
};
F8C83FAC272F998A0009DF0D /* Plugin */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -677,8 +692,7 @@
F8FC439F26C01EFC0033E151 /* Protocols */ = {
isa = PBXGroup;
children = (
F8FC43B226C020B90033E151 /* BackCardCreationDelegate.swift */,
F8C310BF273A7360008EC5BA /* FrontCardCreationDelegate.swift */,
F8915A1F275713A10013D609 /* CardCreation */,
);
path = Protocols;
sourceTree = "<group>";
Expand Down Expand Up @@ -977,7 +991,9 @@
F822E7A92709CEB60020452C /* Notification.swift in Sources */,
F8C83FC5272FA2940009DF0D /* CardAPI.swift in Sources */,
7729171F2743D604001593E0 /* CardsInGroupResponse.swift in Sources */,
F8915A22275728F20013D609 /* SelectBirthBottomViewController.swift in Sources */,
F8FC438626C01CDD0033E151 /* AppDelegate.swift in Sources */,
F8915A23275728F20013D609 /* SelectMBTIBottomViewController.swift in Sources */,
F8C83FB8272F9E3F0009DF0D /* UtilAPI.swift in Sources */,
F8FC438826C01CDD0033E151 /* SceneDelegate.swift in Sources */,
39288E12273F52B20072F403 /* CardListLookUpRequest.swift in Sources */,
Expand Down
7 changes: 4 additions & 3 deletions NADA-iOS-forRelease/Resouces/Constants/Notification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import Foundation

extension Notification.Name {
// delegate 패턴으로 대체
// static let frontCardtextFieldIsEmpty = Notification.Name("frontCardtextFieldIsEmpty")
// static let backCardtextFieldIsEmpty = Notification.Name("backCardtextFieldIsEmpty")
static let deleteTabBar = NSNotification.Name("deleteTabBar")
static let expressTabBar = NSNotification.Name("expressTabBar")

// MARK: - Card Creation
static let frontCardBirth = Notification.Name("frontCardBirth")
static let frontCardMBTI = Notification.Name("frontCardMBTI")
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ import UIKit

class FrontCardCreationCollectionViewCell: UICollectionViewCell {

// MARK: - Protocols

public weak var frontCardCreationDelegate: FrontCardCreationDelegate?

// MARK: - Properties

private let backgroundList = ["img", "img", "img", "img", "img"]
private var requiredTextFieldList = [UITextField]()
private var optionalTextFieldList = [UITextField]()
public weak var frontCardCreationDelegate: FrontCardCreationDelegate?
public var presentingBirthBottomVCClosure: (() -> Void)?
public var presentingMBTIBottomVCClosure: (() -> Void)?

// MARK: - @IBOutlet Properties

Expand Down Expand Up @@ -44,6 +49,7 @@ class FrontCardCreationCollectionViewCell: UICollectionViewCell {
setUI()
registerCell()
textFieldDelegate()
setNotification()
}
}

Expand Down Expand Up @@ -97,7 +103,7 @@ extension FrontCardCreationCollectionViewCell {
NSAttributedString.Key.foregroundColor: UIColor.quaternary
])

instagramIDTextField.attributedPlaceholder = NSAttributedString(string: "Instagram", attributes: [
instagramIDTextField.attributedPlaceholder = NSAttributedString(string: "Instagram (@ 제외)", attributes: [
NSAttributedString.Key.foregroundColor: UIColor.quaternary
])
linkURLTextField.attributedPlaceholder = NSAttributedString(string: "URL (Github, Blog)", attributes: [
Expand Down Expand Up @@ -147,9 +153,29 @@ extension FrontCardCreationCollectionViewCell {
_ = requiredTextFieldList.map { $0.delegate = self }
_ = optionalTextFieldList.map { $0.delegate = self }
}
private func setNotification() {
NotificationCenter.default.addObserver(self, selector: #selector(setBirthTextField(notification:)), name: .frontCardBirth, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(setMBTITextField(notification:)), name: .frontCardMBTI, object: nil)
}
static func nib() -> UINib {
return UINib(nibName: Const.Xib.frontCardCreationCollectionViewCell, bundle: Bundle(for: FrontCardCreationCollectionViewCell.self))
}

// MARK: - @objc Methods

@objc
private func setBirthTextField(notification: NSNotification) {
birthTextField.text = notification.object as? String

birthTextField.borderWidth = 0
}

@objc
private func setMBTITextField(notification: NSNotification) {
mbtiTextField.text = notification.object as? String

mbtiTextField.borderWidth = 0
}
}

// MARK: - UICollectionViewDelegate
Expand Down Expand Up @@ -190,9 +216,16 @@ extension FrontCardCreationCollectionViewCell: UICollectionViewDelegateFlowLayou
// MARK: - UITextFieldDelegate
extension FrontCardCreationCollectionViewCell: UITextFieldDelegate {
func textFieldDidBeginEditing(_ textField: UITextField) {
textField.borderWidth = 1
textField.borderColor = .tertiary
textField.becomeFirstResponder()
if textField == birthTextField {
textField.endEditing(true)
presentingBirthBottomVCClosure?()
} else if textField == mbtiTextField {
textField.endEditing(true)
presentingMBTIBottomVCClosure?()
} else {
textField.borderWidth = 1
textField.borderColor = .tertiary
}
}
func textFieldDidEndEditing(_ textField: UITextField) {
frontCardCreationDelegate?.frontCardCreation(endEditing: true)
Expand All @@ -215,6 +248,7 @@ extension FrontCardCreationCollectionViewCell: UITextFieldDelegate {
} else {
frontCardCreationDelegate?.frontCardCreation(requiredInfo: false)
}
textField.resignFirstResponder()
textField.borderWidth = 0
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
//
// SelectBirthBottomViewController.swift
// NADA-iOS-forRelease
//
// Created by kimhyungyu on 2021/11/30.
//

import UIKit

class SelectBirthBottomSheetViewController: CommonBottomSheetViewController {

// MARK: - Properties

private let yearList: [String] = [Int](1950...2021).map { String($0) }.reversed()
private let monthList: [String] = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"]
private let dayList: [String] = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"]
private var year = String()
private var month = String()
private var day = String()
private var selectedBirth = String()

// MARK: - Components

private let birthPicker: UIPickerView = {
let pickerView = UIPickerView()

return pickerView
}()

private let doneButton: UIButton = {
let button = UIButton()
button.setImage(UIImage(named: "btnMainDone"), for: .normal)
button.addTarget(self, action: #selector(dismissToCardCreationViewController), for: .touchUpInside)

return button
}()

// MARK: - View Life Cycle

override func viewDidLoad() {
super.viewDidLoad()

setupUI()
}
}

// MARK: - Extensions

extension SelectBirthBottomSheetViewController {
private func setupUI() {
view.addSubview(birthPicker)
view.addSubview(doneButton)

selectedBirth = yearList[0] + "/" + monthList[0] + "/" + dayList[0]

birthPicker.delegate = self
birthPicker.dataSource = self

setupLayout()
}
private func setupLayout() {
birthPicker.selectedRow(inComponent: 0)
birthPicker.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
birthPicker.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: -20),
birthPicker.centerXAnchor.constraint(equalTo: bottomSheetView.centerXAnchor),
birthPicker.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16),
birthPicker.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -16)
])

doneButton.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
doneButton.topAnchor.constraint(equalTo: birthPicker.bottomAnchor, constant: 0),
doneButton.centerXAnchor.constraint(equalTo: bottomSheetView.centerXAnchor),
doneButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 24),
doneButton.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -24)
])
}

// MARK: - @objc Methods

@objc func dismissToCardCreationViewController() {
NotificationCenter.default.post(name: .frontCardBirth, object: selectedBirth)
dismiss(animated: true, completion: nil)
}

}

extension SelectBirthBottomSheetViewController: UIPickerViewDelegate, UIPickerViewDataSource {
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 3
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
if component == 0 {
return yearList.count
} else if component == 1 {
return monthList.count
} else {
return dayList.count
}
}

func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
let label = (view as? UILabel) ?? UILabel()

label.textAlignment = .center

if component == 0 {
if pickerView.selectedRow(inComponent: component) == row {
label.attributedText = NSAttributedString(string: yearList[row], attributes: [NSAttributedString.Key.font: UIFont.textBold01, NSAttributedString.Key.foregroundColor: UIColor.mainColorNadaMain])

} else {
label.attributedText = NSAttributedString(string: yearList[row], attributes: [NSAttributedString.Key.font: UIFont.textRegular03, NSAttributedString.Key.foregroundColor: UIColor.quaternary])
}
} else if component == 1 {
if pickerView.selectedRow(inComponent: component) == row {
label.attributedText = NSAttributedString(string: monthList[row], attributes: [NSAttributedString.Key.font: UIFont.textBold01, NSAttributedString.Key.foregroundColor: UIColor.mainColorNadaMain])

} else {
label.attributedText = NSAttributedString(string: monthList[row], attributes: [NSAttributedString.Key.font: UIFont.textRegular03, NSAttributedString.Key.foregroundColor: UIColor.quaternary])
}
} else if component == 2 {
if pickerView.selectedRow(inComponent: component) == row {
label.attributedText = NSAttributedString(string: dayList[row], attributes: [NSAttributedString.Key.font: UIFont.textBold01, NSAttributedString.Key.foregroundColor: UIColor.mainColorNadaMain])

} else {
label.attributedText = NSAttributedString(string: dayList[row], attributes: [NSAttributedString.Key.font: UIFont.textRegular03, NSAttributedString.Key.foregroundColor: UIColor.quaternary])
}
}

return label
}

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
pickerView.reloadAllComponents()

if component == 0 {
year = yearList[row]
} else if component == 1 {
month = monthList[row]
} else if component == 2 {
day = dayList[row]
}
year = year.isEmpty ? yearList[0] : year
month = month.isEmpty ? monthList[0] : month
day = day.isEmpty ? dayList[0] : day
selectedBirth = year + "/" + month + "/" + day
}

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

0 comments on commit de3d09a

Please sign in to comment.