Skip to content

Commit

Permalink
Merge pull request #15 from Team-HMH/feat/#11-pickerViewUI
Browse files Browse the repository at this point in the history
Feat [#11] CreateChallenge - pickerView 구현
  • Loading branch information
kim-seonwoo authored Jan 5, 2024
2 parents bfb2836 + 97dba51 commit 828a0ed
Show file tree
Hide file tree
Showing 4 changed files with 265 additions and 114 deletions.
28 changes: 24 additions & 4 deletions HMH_iOS/HMH_iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/* Begin PBXBuildFile section */
0B0035402B43D64D00DA140C /* HMHNavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B00353F2B43D64D00DA140C /* HMHNavigationBar.swift */; };
0B2C2D3B2B443BE90023CCFA /* Image.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B2C2D3A2B443BE90023CCFA /* Image.swift */; };
0B2C2D3F2B4559E10023CCFA /* OnboardingButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B2C2D3E2B4559E10023CCFA /* OnboardingButton.swift */; };
0B2C2D412B4572240023CCFA /* HMHSelectButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B2C2D402B4572240023CCFA /* HMHSelectButton.swift */; };
0B50F9CB2B369813000C5046 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B50F9CA2B369813000C5046 /* AppDelegate.swift */; };
0B50F9CD2B369813000C5046 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B50F9CC2B369813000C5046 /* SceneDelegate.swift */; };
Expand All @@ -34,7 +33,6 @@
174AF4982B447CF100450D07 /* ChanllengeModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 174AF4972B447CF100450D07 /* ChanllengeModels.swift */; };
174AF49A2B447CFB00450D07 /* ChanllengeViews.swift in Sources */ = {isa = PBXBuildFile; fileRef = 174AF4992B447CFB00450D07 /* ChanllengeViews.swift */; };
174AF49C2B447D0700450D07 /* ChanllengeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 174AF49B2B447D0700450D07 /* ChanllengeViewController.swift */; };
174AF49E2B447E8600450D07 /* TabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 174AF49D2B447E8600450D07 /* TabBarController.swift */; };
3666C84D2B45F41300564874 /* HMHAppSelectButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3666C84C2B45F41300564874 /* HMHAppSelectButtonView.swift */; };
3666C8552B45F47600564874 /* DeviceActivity.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3666C8542B45F47600564874 /* DeviceActivity.framework */; };
3666C8582B45F47600564874 /* DeviceActivityMonitorExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3666C8572B45F47600564874 /* DeviceActivityMonitorExtension.swift */; };
Expand All @@ -45,6 +43,8 @@
3666C8722B45F4B200564874 /* DeviceReport.appex in Embed ExtensionKit Extensions */ = {isa = PBXBuildFile; fileRef = 3666C8662B45F4B200564874 /* DeviceReport.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
3666C87A2B45F4F900564874 /* SelectedBlocker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3666C8792B45F4F900564874 /* SelectedBlocker.swift */; };
3666C87C2B45F50F00564874 /* BlockingApplicationModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3666C87B2B45F50F00564874 /* BlockingApplicationModel.swift */; };
3666C8882B47110800564874 /* SpecificTimePickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3666C8862B47110800564874 /* SpecificTimePickerView.swift */; };
3666C8892B47110800564874 /* TotalTimePickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3666C8872B47110800564874 /* TotalTimePickerView.swift */; };
36A3D8942B3AB57B007EA272 /* SnapKit in Frameworks */ = {isa = PBXBuildFile; productRef = 36A3D8932B3AB57B007EA272 /* SnapKit */; };
36A3D8962B3AB57B007EA272 /* SnapKit-Dynamic in Frameworks */ = {isa = PBXBuildFile; productRef = 36A3D8952B3AB57B007EA272 /* SnapKit-Dynamic */; };
36A3D8992B3AB58A007EA272 /* Then in Frameworks */ = {isa = PBXBuildFile; productRef = 36A3D8982B3AB58A007EA272 /* Then */; };
Expand Down Expand Up @@ -150,7 +150,6 @@
174AF4972B447CF100450D07 /* ChanllengeModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChanllengeModels.swift; sourceTree = "<group>"; };
174AF4992B447CFB00450D07 /* ChanllengeViews.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChanllengeViews.swift; sourceTree = "<group>"; };
174AF49B2B447D0700450D07 /* ChanllengeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChanllengeViewController.swift; sourceTree = "<group>"; };
174AF49D2B447E8600450D07 /* TabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarController.swift; sourceTree = "<group>"; };
3666C84C2B45F41300564874 /* HMHAppSelectButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HMHAppSelectButtonView.swift; sourceTree = "<group>"; };
3666C8522B45F47600564874 /* DeviceMonitor.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = DeviceMonitor.appex; sourceTree = BUILT_PRODUCTS_DIR; };
3666C8542B45F47600564874 /* DeviceActivity.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DeviceActivity.framework; path = System/Library/Frameworks/DeviceActivity.framework; sourceTree = SDKROOT; };
Expand All @@ -166,6 +165,8 @@
3666C8772B45F4C600564874 /* HMH_iOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = HMH_iOS.entitlements; sourceTree = "<group>"; };
3666C8792B45F4F900564874 /* SelectedBlocker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectedBlocker.swift; sourceTree = "<group>"; };
3666C87B2B45F50F00564874 /* BlockingApplicationModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlockingApplicationModel.swift; sourceTree = "<group>"; };
3666C8862B47110800564874 /* SpecificTimePickerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpecificTimePickerView.swift; sourceTree = "<group>"; };
3666C8872B47110800564874 /* TotalTimePickerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TotalTimePickerView.swift; sourceTree = "<group>"; };
36A3D9B32B3EBBED007EA272 /* UIStackView+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIStackView+.swift"; sourceTree = "<group>"; };
36A3D9B52B3EBBF7007EA272 /* Adjust+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Adjust+.swift"; sourceTree = "<group>"; };
36A3D9B72B3EBC3B007EA272 /* UILabel+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UILabel+.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -310,6 +311,7 @@
0B67CCE72B369BE300582D54 /* Presentation */ = {
isa = PBXGroup;
children = (
3666C8842B47110800564874 /* CreateChallenge */,
174AF4842B447AB500450D07 /* MyPage */,
174AF4832B447A7A00450D07 /* Challenge */,
0B2C2D3C2B4559AE0023CCFA /* Onboarding */,
Expand Down Expand Up @@ -498,7 +500,6 @@
174AF4362B43DB2000450D07 /* CustomTabbar */ = {
isa = PBXGroup;
children = (
174AF49D2B447E8600450D07 /* TabBarController.swift */,
);
path = CustomTabbar;
sourceTree = "<group>";
Expand Down Expand Up @@ -636,6 +637,23 @@
path = AppBlock;
sourceTree = "<group>";
};
3666C8842B47110800564874 /* CreateChallenge */ = {
isa = PBXGroup;
children = (
3666C8852B47110800564874 /* Views */,
);
path = CreateChallenge;
sourceTree = "<group>";
};
3666C8852B47110800564874 /* Views */ = {
isa = PBXGroup;
children = (
3666C8862B47110800564874 /* SpecificTimePickerView.swift */,
3666C8872B47110800564874 /* TotalTimePickerView.swift */,
);
path = Views;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -811,11 +829,13 @@
36A3D9B82B3EBC3B007EA272 /* UILabel+.swift in Sources */,
0B50F9CB2B369813000C5046 /* AppDelegate.swift in Sources */,
0B8A89C42B369FA000688BA6 /* F.swift in Sources */,
3666C8892B47110800564874 /* TotalTimePickerView.swift in Sources */,
174AF49A2B447CFB00450D07 /* ChanllengeViews.swift in Sources */,
0B8A89B72B369F1100688BA6 /* C.swift in Sources */,
0B2C2D3B2B443BE90023CCFA /* Image.swift in Sources */,
3666C84D2B45F41300564874 /* HMHAppSelectButtonView.swift in Sources */,
0B8A89AD2B369E3B00688BA6 /* HomeCell.swift in Sources */,
3666C8882B47110800564874 /* SpecificTimePickerView.swift in Sources */,
174AF4922B447B4600450D07 /* MyPageViews.swift in Sources */,
0B8A89C62B369FA800688BA6 /* H.swift in Sources */,
36A3D9BE2B409BCC007EA272 /* Color.swift in Sources */,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
//
// SpecificTimePickerView.swift
// HMH_iOS
//
// Created by Seonwoo Kim on 1/4/24.
//

import UIKit

import SnapKit
import Then

final class SpecificTimePickerView: UIPickerView {
private let hours: [String] = ["0", "1"]
private let minutes: [String] = Array(0...59).map { String($0) }

private let hourLabel = UILabel().then {
$0.textColor = .gray2
$0.font = .iosText2Medium20
$0.text = "시간"
}

private let minuteLabel = UILabel().then {
$0.textColor = .gray2
$0.font = .iosText2Medium20
$0.text = ""
}

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

setUI()
configurePickerView()
setDelegate()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

private func setUI() {
setHierarchy()
setConstraints()
}

private func setHierarchy() {
self.addSubviews(hourLabel, minuteLabel)
}

private func setConstraints() {
hourLabel.snp.makeConstraints {
$0.centerY.equalToSuperview()
$0.leading.equalToSuperview().inset(122.adjusted)
}

minuteLabel.snp.makeConstraints {
$0.centerY.equalToSuperview()
$0.trailing.equalToSuperview().inset(38.adjusted)
}
}

private func setDelegate() {
self.delegate = self
self.dataSource = self
}

private func configurePickerView() {
self.backgroundColor = .clear
}
}

extension SpecificTimePickerView: UIPickerViewDelegate {
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
if component == 0 {
return hours[row]
} else {
return minutes[row]
}
}

var selectedRow: Int {
return self.selectedRow(inComponent: 0)
}

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
self.reloadComponent(component)
}

func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
var color = UIColor.gray3
var font = UIFont.iosText1Medium22

if component == 0 && row == pickerView.selectedRow(inComponent: 0) {
color = UIColor.whiteText
font = UIFont.iosText1Medium22
}

if component == 1 && row == pickerView.selectedRow(inComponent: 1) {
color = UIColor.whiteText
font = UIFont.iosText1Medium22
}

let attributes: [NSAttributedString.Key: Any] = [
NSAttributedString.Key(rawValue: NSAttributedString.Key.foregroundColor.rawValue): color,
NSAttributedString.Key(rawValue: NSAttributedString.Key.font.rawValue): font
]

if component == 0 {
return NSAttributedString(string: hours[row], attributes: attributes)
} else {
return NSAttributedString(string: minutes[row], attributes: attributes)
}
}

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

extension SpecificTimePickerView: UIPickerViewDataSource{
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 2
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
if component == 0 {
return hours.count
} else {
return minutes.count
}
}
}




Loading

0 comments on commit 828a0ed

Please sign in to comment.