From 684eff9b530598c35cfb126edca15569ca80c014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=98=81=EC=9D=B8?= <0inn1220@gmail.com> Date: Mon, 6 Feb 2023 23:03:50 +0900 Subject: [PATCH] =?UTF-8?q?[Style]=20#70=20-=20=EB=AA=A9=ED=91=9C=EC=82=B0?= =?UTF-8?q?=EC=B1=85=EC=8B=9C=EA=B0=84=20=EC=A7=81=EC=A0=91=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20UI=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CustomView/SelectGoalWalkTimeView.swift | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 FootprintIOS/FootprintIOS/Sources/View/Alert/CustomView/SelectGoalWalkTimeView.swift diff --git a/FootprintIOS/FootprintIOS/Sources/View/Alert/CustomView/SelectGoalWalkTimeView.swift b/FootprintIOS/FootprintIOS/Sources/View/Alert/CustomView/SelectGoalWalkTimeView.swift new file mode 100644 index 0000000..972f4a4 --- /dev/null +++ b/FootprintIOS/FootprintIOS/Sources/View/Alert/CustomView/SelectGoalWalkTimeView.swift @@ -0,0 +1,123 @@ +// +// SelectGoalWalkTimeView.swift +// Footprint-iOSTests +// +// Created by 김영인 on 2023/02/05. +// Copyright © 2023 Footprint-iOS. All rights reserved. +// + +import UIKit + +class SelectGoalWalkTimeView: BaseView { + + enum Time: Int { + case hour + case minute + } + + // MARK: - Properties + + private var hours: [String] = [] + private var minutes: [String] = [] + + // MARK: - UI Components + + let pickerView = UIPickerView() + + // MARK: - Methods + + override func setupProperty() { + super.setupProperty() + + setupPickerView() + } + + override func setupDelegate() { + pickerView.delegate = self + pickerView.dataSource = self + } + + override func setupHierarchy() { + addSubview(pickerView) + } + + override func setupLayout() { + pickerView.snp.makeConstraints() { + $0.top.bottom.equalToSuperview() + $0.leading.trailing.equalToSuperview().inset(20) + } + } + + private func setupPickerView() { + for hour in Array(0...23) { + hours.append("\(hour)시간") + } + + for minute in Array(0...5) { + minutes.append("\(minute * 10)분") + } + } +} + +extension SelectGoalWalkTimeView: UIPickerViewDataSource { + func numberOfComponents(in pickerView: UIPickerView) -> Int { + return 2 + } + + func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { + switch component { + case Time.hour.rawValue: + return hours.count + case Time.minute.rawValue: + return minutes.count + default: + return 0 + } + } +} + +extension SelectGoalWalkTimeView: UIPickerViewDelegate { + func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { + switch component { + case Time.hour.rawValue: + return hours[row] + case Time.minute.rawValue: + return minutes[row] + default: + return "" + } + } + + func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { + switch component { + case Time.hour.rawValue: + print(hours[row]) + case Time.minute.rawValue: + print(minutes[row]) + default: + break + } + } + + func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat { + return 40 + } + + func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView { + + let label = UILabel() + label.font = .systemFont(ofSize: 18) + label.textAlignment = .center + + switch component { + case Time.hour.rawValue: + label.text = hours[row] + case Time.minute.rawValue: + label.text = minutes[row] + default: + break + } + + return label + } +}