Skip to content

Commit

Permalink
Merge pull request #343 from TeamNADA/feature/#336
Browse files Browse the repository at this point in the history
fix: SelectBirthBottomViewController 에서 피커뷰 변경 (#336)
  • Loading branch information
hyun99999 authored Jan 31, 2023
2 parents 4992bba + 735e373 commit 9827e58
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 41 deletions.
6 changes: 4 additions & 2 deletions NADA-iOS-forRelease.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
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 */; };
F8810203298826FC007266B5 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = F8810202298826FC007266B5 /* GoogleService-Info.plist */; };
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 */; };
Expand Down Expand Up @@ -272,6 +273,7 @@
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>"; };
F8810202298826FC007266B5 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; 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>"; };
Expand Down Expand Up @@ -814,7 +816,7 @@
F8FC439926C01E2B0033E151 /* Resouces */ = {
isa = PBXGroup;
children = (
F837AB7C2965582C00A8804A /* GoogleService-Info.plist */,
F8810202298826FC007266B5 /* GoogleService-Info.plist */,
F857FC8A26C03A5C00A48D01 /* Assets */,
39DA4D7B2747D7060082D572 /* Font */,
F8562C94296ADC0A00DA1109 /* Lottie */,
Expand Down Expand Up @@ -1028,6 +1030,7 @@
files = (
F8518058275D042B006BD5ED /* Onboarding.storyboard in Resources */,
F8FC43BF26C025180033E151 /* .swiftlint.yml in Resources */,
F8810203298826FC007266B5 /* GoogleService-Info.plist in Resources */,
397B75142763A916004AEB03 /* OpenSourceTableViewCell.xib in Resources */,
F85711A7274A6B3400F59F0B /* CardCreationPreview.storyboard in Resources */,
77607EDB274A68BE00204CD2 /* GroupCollectionViewCell.xib in Resources */,
Expand Down Expand Up @@ -1068,7 +1071,6 @@
F82FF81D2701EBCE00E57F8B /* CardCreation.storyboard in Resources */,
39369937274A4FCB00684420 /* NotoSansCJKkr-Medium.otf in Resources */,
392F7FB5274621F1008CDBF5 /* MoreListTableViewCell.xib in Resources */,
F837AB7D2965582C00A8804A /* GoogleService-Info.plist in Resources */,
7770315927500C49002CBD19 /* QRScan.storyboard in Resources */,
390515B82706CEBB00C5F7A5 /* Colors.xcassets in Resources */,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ class SelectBirthBottomSheetViewController: CommonBottomSheetViewController {
// FIXME: - 명함생성뷰에서 날짜를 넘길때 에러.(0.0.0 이 아닌 0월 0일로 반영)
private var selectedBirth = String()

@frozen
private enum Column: Int, CaseIterable {
case month = 0
case day = 1
}

// MARK: - Components

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

return pickerView
}()

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

return pickerView
Expand Down Expand Up @@ -62,29 +62,40 @@ class SelectBirthBottomSheetViewController: CommonBottomSheetViewController {

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

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

birthPicker.delegate = self
birthPicker.dataSource = self
monthPicker.delegate = self
monthPicker.dataSource = self
dayPicker.delegate = self
dayPicker.dataSource = self

setupLayout()
}

private func setupLayout() {
birthPicker.selectedRow(inComponent: 0)
birthPicker.translatesAutoresizingMaskIntoConstraints = false
monthPicker.selectedRow(inComponent: 0)
monthPicker.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
monthPicker.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: -20),
monthPicker.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16),
monthPicker.widthAnchor.constraint(equalToConstant: (view.frame.width - 32) / 2)
])

dayPicker.selectedRow(inComponent: 0)
dayPicker.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)
dayPicker.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: -20),
dayPicker.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -16),
dayPicker.widthAnchor.constraint(equalToConstant: (view.frame.width - 32) / 2)
])

doneButton.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
doneButton.topAnchor.constraint(equalTo: birthPicker.bottomAnchor, constant: 0),
doneButton.topAnchor.constraint(equalTo: monthPicker.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)
Expand All @@ -97,61 +108,55 @@ extension SelectBirthBottomSheetViewController {
NotificationCenter.default.post(name: .completeFrontCardBirth, object: selectedBirth)
hideBottomSheetAndGoBack()
}

}

extension SelectBirthBottomSheetViewController: UIPickerViewDelegate, UIPickerViewDataSource {
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return Column.allCases.count
return 1
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
guard let row = Column(rawValue: component) else { return 0 }

switch row {
case .month:
if pickerView == monthPicker {
return monthList.count
case .day:
} else {
return dayList.count
}
}

func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
let backgroundView = pickerView.subviews[1]
backgroundView.cornerRadius = 23
backgroundView.frame = CGRect(x: backgroundView.frame.minX, y: backgroundView.frame.minY, width: backgroundView.frame.width, height: 44)

let label = (view as? UILabel) ?? UILabel()

label.textAlignment = .center

guard let colum = Column(rawValue: component) else { return label }

switch colum {
case .month:
if pickerView == monthPicker {
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])
}
case .day:
} else {
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
}

return label
}

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

guard let colum = Column(rawValue: component) else { return }

switch colum {
case .month:
if pickerView == monthPicker {
month = monthList[row]
case .day:
} else {
day = dayList[row]
}

Expand Down

0 comments on commit 9827e58

Please sign in to comment.