Skip to content

Commit

Permalink
πŸ”€:: #178 from MaeumgaGym/feature/#171-timerViewFinish
Browse files Browse the repository at this point in the history
βš“οΈ :: [#171] 타이머 View μž‘μ—…
  • Loading branch information
jjunhaa0211 authored Feb 15, 2024
2 parents bd5c3f8 + d4b7815 commit dd5c595
Show file tree
Hide file tree
Showing 2 changed files with 235 additions and 0 deletions.
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)
}

}
}
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
}
}


}

0 comments on commit dd5c595

Please sign in to comment.