-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
βοΈ :: [#171] νμ΄λ¨Έ View μμ
- Loading branch information
Showing
2 changed files
with
235 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
Projects/Features/HomeFeature/Sources/TimerScene/Supporter/AddTimerView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import UIKit | ||
|
||
import SnapKit | ||
import Then | ||
|
||
import Core | ||
import DSKit | ||
|
||
public class AddTimerView: BaseView { | ||
|
||
private var containerView = UIView().then { | ||
$0.backgroundColor = UIColor.black.withAlphaComponent(0.4) | ||
} | ||
|
||
private let timerAddBackView = UIView().then { | ||
$0.backgroundColor = .white | ||
$0.layer.cornerRadius = 20.0 | ||
} | ||
|
||
private let addTimerLabel = UILabel().then { | ||
$0.text = "νμ΄λ¨Έ μΆκ°" | ||
$0.font = UIFont.Pretendard.titleMedium | ||
$0.textAlignment = .left | ||
$0.textColor = .black | ||
} | ||
|
||
private let timerPickerView = TimerPickerView() | ||
|
||
public override func layout() { | ||
addSubviews([containerView]) | ||
containerView.addSubviews([timerAddBackView]) | ||
timerAddBackView.addSubviews([addTimerLabel, timerPickerView]) | ||
|
||
containerView.snp.makeConstraints { | ||
$0.edges.equalToSuperview() | ||
} | ||
|
||
timerAddBackView.snp.makeConstraints { | ||
$0.leading.trailing.equalToSuperview() | ||
$0.bottom.equalTo(containerView.safeAreaLayoutGuide) | ||
$0.top.equalTo(containerView.snp.centerY).offset(-62.0) | ||
} | ||
|
||
addTimerLabel.snp.makeConstraints { | ||
$0.top.equalToSuperview().offset(24.0) | ||
$0.leading.trailing.equalToSuperview().inset(20.0) | ||
$0.height.equalTo(32.0) | ||
} | ||
|
||
timerPickerView.snp.makeConstraints { | ||
$0.leading.trailing.equalToSuperview().inset(20.0) | ||
$0.top.equalToSuperview().offset(80.0) | ||
$0.bottom.equalToSuperview().offset(-74.0) | ||
} | ||
|
||
} | ||
} |
178 changes: 178 additions & 0 deletions
178
Projects/Features/HomeFeature/Sources/TimerScene/Supporter/TimerPickerView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
import UIKit | ||
|
||
import SnapKit | ||
import Then | ||
|
||
import Core | ||
import DSKit | ||
|
||
public class TimerPickerView: BaseView { | ||
private var pickerWidth: Double = 75.0 | ||
public var isFirstLoad: Bool? | ||
|
||
public var pickerSelectValue = 0 | ||
|
||
|
||
private let hourValues: [Int] = [00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23] | ||
|
||
private let minuteValues: [Int] = [00, 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, 32, 33, 34, 35, 36, 37, 38, 39, 40, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59] | ||
|
||
private let secondValues: [Int] = [00, 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, 32, 33, 34, 35, 36, 37, 38, 39, 40, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59] | ||
|
||
|
||
private var rotationAngle: CGFloat! = -90 * (.pi/180) | ||
|
||
lazy var pickerView = UIPickerView().then { | ||
$0.transform = CGAffineTransform(rotationAngle: 0) | ||
} | ||
|
||
private lazy var titleLabel = UILabel().then { | ||
$0.textAlignment = .center | ||
$0.font = UIFont.Pretendard.light | ||
$0.textColor = .black | ||
} | ||
|
||
lazy var pickerSetLabel = UILabel() | ||
|
||
public override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
} | ||
|
||
required public init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
public override func layout() { | ||
addSubviews([pickerView]) | ||
|
||
pickerView.snp.makeConstraints { | ||
$0.leading.trailing.equalToSuperview().inset(43.5) | ||
$0.top.equalToSuperview().offset(14.0) | ||
$0.bottom.equalToSuperview().inset(10.0) | ||
} | ||
|
||
} | ||
|
||
public override func attribute() { | ||
pickerView.delegate = self | ||
pickerView.dataSource = self | ||
|
||
if #available(iOS 14.0, *) { | ||
pickerView.preferredDatePickerStyle = .inline | ||
} | ||
} | ||
|
||
} | ||
|
||
extension TimerPickerView: UIPickerViewDelegate { | ||
public func numberOfComponents(in pickerView: UIPickerView) -> Int { | ||
return 3 | ||
} | ||
|
||
public func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { | ||
switch component { | ||
case 0: | ||
return "\(hourValues[row])" | ||
case 1: | ||
return "\(minuteValues[row])" | ||
case 2: | ||
return "\(secondValues[row])" | ||
default: | ||
return "" | ||
} | ||
} | ||
|
||
public func pickerView(_ pickerView: UIPickerView, | ||
rowHeightForComponent component: Int | ||
) -> CGFloat { | ||
return 48.0 | ||
} | ||
|
||
public func pickerView(_ pickerView: UIPickerView, | ||
viewForRow row: Int, | ||
forComponent component: Int, | ||
reusing view: UIView? | ||
) -> UIView { | ||
|
||
let pickerRow = UIView() | ||
pickerRow.frame = CGRect(x: 0, y: 0, width: pickerWidth, height: 128.0) | ||
|
||
lazy var rowLabel = UILabel().then { | ||
$0.textColor = .black | ||
$0.font = UIFont.Pretendard.light | ||
$0.textAlignment = .center | ||
$0.layer.masksToBounds = true | ||
$0.backgroundColor = .white | ||
} | ||
|
||
pickerRow.addSubview(rowLabel) | ||
rowLabel.snp.makeConstraints { | ||
$0.center.equalTo(pickerRow.snp.center) // λ μ΄λΈμ UIViewμ μ€μμ μμΉμν΄ | ||
$0.width.equalTo(pickerRow.snp.width) | ||
$0.height.equalTo(48) // λ μ΄λΈμ λμ΄λ₯Ό 48λ‘ μ€μ | ||
} | ||
|
||
switch component { | ||
case 0: | ||
rowLabel.text = "\(hourValues[row])" | ||
case 1: | ||
rowLabel.text = "\(minuteValues[row])" | ||
case 2: | ||
rowLabel.text = "\(secondValues[row])" | ||
default: | ||
rowLabel.text = "" | ||
} | ||
|
||
|
||
pickerRow.transform = CGAffineTransform(rotationAngle: 0) | ||
|
||
guard let myBool = isFirstLoad else { | ||
return pickerRow | ||
} | ||
|
||
guard !myBool else { | ||
return pickerRow | ||
} | ||
|
||
guard let selectView = pickerView.view(forRow: pickerSelectValue, forComponent: component) else { | ||
return pickerRow | ||
} | ||
|
||
let selectLabel = selectView.subviews[0] as! UILabel | ||
selectLabel.textColor = .black | ||
selectLabel.font = UIFont.Pretendard.light | ||
return pickerRow | ||
} | ||
|
||
public func pickerView(_ pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat { | ||
switch component { | ||
case 0: | ||
return pickerWidth + 38.5 | ||
case 1: | ||
return pickerWidth + 38.5 | ||
case 2: | ||
return pickerWidth | ||
default: | ||
return 0 | ||
} | ||
} | ||
|
||
} | ||
|
||
extension TimerPickerView: UIPickerViewDataSource { | ||
|
||
public func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { | ||
switch component { | ||
case 0: | ||
return hourValues.count | ||
case 1: | ||
return minuteValues.count | ||
case 2: | ||
return secondValues.count | ||
default: | ||
return 0 | ||
} | ||
} | ||
|
||
|
||
} |