Skip to content

Commit

Permalink
#24 약 디테일 페이지 UI 완성
Browse files Browse the repository at this point in the history
  • Loading branch information
doyeonk429 committed Nov 22, 2024
1 parent 88fdc03 commit 3667cb7
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"images" : [
{
"filename" : "광진구.png",
"filename" : "광진구@2x.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "광진구@2x.png",
"filename" : "광진구.png",
"idiom" : "universal",
"scale" : "2x"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import UIKit
class EnrollDetailViewController: UIViewController {

private lazy var backButton: CustomBackButton = {
let button = CustomBackButton(title: " 의약품 삭제하기")
let button = CustomBackButton(title: " 의약품 등록하기")
button.addTarget(self, action: #selector(didTapBackButton), for: .touchUpInside)
return button
}()
Expand All @@ -23,6 +23,7 @@ class EnrollDetailViewController: UIViewController {
let picker = UIDatePicker()
picker.datePickerMode = .date // 날짜 선택 모드
picker.preferredDatePickerStyle = .inline
picker.tintColor = Constants.Colors.skyblue
picker.locale = Locale(identifier: "ko_KR") // 한국어로 표시
picker.addTarget(self, action: #selector(dateChanged(_:)), for: .valueChanged)
return picker
Expand All @@ -36,34 +37,64 @@ class EnrollDetailViewController: UIViewController {
label.font = UIFont.ptdSemiBoldFont(ofSize: 17)
return label
}()

private lazy var customStepper: CustomStepper = {
let stepper = CustomStepper()
return stepper
}()

private lazy var completeButton: UIButton = {
let button = UIButton()
button.setTitle("저장하기", for: .normal)
button.backgroundColor = Constants.Colors.skyblue
button.setTitleColor(.white, for: .normal)
button.layer.cornerRadius = 25
button.titleLabel?.font = UIFont.ptdSemiBoldFont(ofSize: 16)
button.addTarget(self, action: #selector(didTapCompleteButton), for: .touchUpInside)
return button
}()

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: backButton)

setupLayout()
}

func setupLayout() {
let views = [selectStartDateLabel, selectDateCountLabel, datePicker]
let views = [selectStartDateLabel, selectDateCountLabel, customStepper, datePicker, completeButton]
views.forEach { view.addSubview($0) }

selectStartDateLabel.snp.makeConstraints { l in
l.top.equalToSuperview().offset(12)
l.leading.equalToSuperview().offset(20)
l.height.equalTo(48)
selectStartDateLabel.snp.makeConstraints { make in
make.top.equalTo(view.safeAreaLayoutGuide).offset(12)
make.leading.equalToSuperview().offset(20) // 좌측 여백
make.height.equalTo(48) // 고정 높이
}

datePicker.snp.makeConstraints { make in
make.top.equalTo(selectStartDateLabel.snp.bottom).offset(10)
make.leading.equalToSuperview().offset(30)
make.trailing.equalToSuperview().offset(-30)
make.height.equalTo(datePicker.snp.width)
make.top.equalTo(selectStartDateLabel.snp.bottom).offset(8) // 위 레이블과의 간격
make.leading.equalToSuperview().offset(30) // 좌측 여백
make.trailing.equalToSuperview().offset(-30) // 우측 여백
make.height.equalTo(datePicker.snp.width) // 정사각형
}

selectDateCountLabel.snp.makeConstraints { make in
make.top.equalTo(datePicker.snp.bottom).offset(16)
make.leading.equalTo(selectStartDateLabel.snp.leading)
make.height.equalTo(48)
make.top.equalTo(datePicker.snp.bottom).offset(16) // 데이트 피커와의 간격
make.leading.equalTo(selectStartDateLabel.snp.leading) // 레이블 정렬
make.height.equalTo(48) // 고정 높이
}

customStepper.snp.makeConstraints { make in
make.top.equalTo(selectDateCountLabel.snp.bottom).offset(28)
make.centerX.equalToSuperview()
make.height.equalTo(35)
}

completeButton.snp.makeConstraints { make in
make.left.right.equalToSuperview().inset(16)
make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom).offset(-16)
make.height.equalTo(50)
}
}

Expand All @@ -72,11 +103,16 @@ class EnrollDetailViewController: UIViewController {
navigationController?.popViewController(animated: false)
}

@objc private func didTapCompleteButton() {

}

@objc private func dateChanged(_ sender: UIDatePicker) {
let formatter = DateFormatter()
formatter.dateStyle = .medium
formatter.locale = Locale(identifier: "ko_KR")
// selectedDateLabel.text = "선택된 날짜: \(formatter.string(from: sender.date))"
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ class PrescriptionDrugVC: UIViewController {
setupGestures()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.isNavigationBarHidden = true
}

// MARK: - Setup Methods

func setupView() {
Expand Down Expand Up @@ -126,15 +131,16 @@ class PrescriptionDrugVC: UIViewController {
// MARK: - Actions

@objc func addDrugViewTapped() {
//TODO: 약 등록하기 VC로 연결
self.navigationController?.isNavigationBarHidden = false
let detailVC = EnrollDetailViewController()
detailVC.hidesBottomBarWhenPushed = true
navigationController?.pushViewController(detailVC, animated: false)
}

@objc func discardButtonTapped(){
self.navigationController?.isNavigationBarHidden = false
let DiscardPrescriptionDrugVC = DiscardPrescriptionDrugVC()
DiscardPrescriptionDrugVC.hidesBottomBarWhenPushed = true
navigationController?.pushViewController(DiscardPrescriptionDrugVC, animated: false)
}
}
Expand Down
102 changes: 102 additions & 0 deletions DropDrug/Sources/Views/CustomStepper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Copyright © 2024 RT4. All rights reserved

import UIKit
import SnapKit

class CustomStepper: UIView {

// MARK: - UI Elements
private lazy var minusButton: UIButton = {
let button = UIButton()
button.setImage(UIImage(systemName: "minus"), for: .normal)
button.imageView?.tintColor = Constants.Colors.gray400
button.backgroundColor = Constants.Colors.gray0
button.layer.cornerRadius = 2
button.contentVerticalAlignment = .center
button.contentHorizontalAlignment = .center
button.addTarget(self, action: #selector(didTapMinus), for: .touchUpInside)
return button
}()

private lazy var plusButton: UIButton = {
let button = UIButton()
button.setImage(UIImage(systemName: "plus"), for: .normal)
button.imageView?.tintColor = Constants.Colors.skyblue
button.backgroundColor = Constants.Colors.gray0
button.layer.cornerRadius = 2
button.contentVerticalAlignment = .center
button.contentHorizontalAlignment = .center
button.addTarget(self, action: #selector(didTapPlus), for: .touchUpInside)
return button
}()

private lazy var numberLabel: UILabel = {
let label = UILabel()
label.text = "0"
label.textColor = Constants.Colors.gray900
label.backgroundColor = Constants.Colors.gray100
label.font = UIFont.ptdSemiBoldFont(ofSize: 22)
label.textAlignment = .center
label.layer.cornerRadius = 2
return label
}()

// MARK: - Properties
public var currentValue: Int = 0 {
didSet {
numberLabel.text = "\(currentValue)"
}
}

// MARK: - Initializer
override init(frame: CGRect) {
super.init(frame: frame)
setupViews()
setupConstraints()
}

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

// MARK: - Setup Views
private func setupViews() {
addSubview(minusButton)
addSubview(numberLabel)
addSubview(plusButton)
}

// MARK: - Setup Constraints
private func setupConstraints() {
minusButton.snp.makeConstraints { make in
make.top.bottom.leading.equalToSuperview()
make.width.equalTo(35) // 버튼 고정 너비
make.height.equalTo(35)
}

numberLabel.snp.makeConstraints { make in
make.top.bottom.equalToSuperview()
make.leading.equalTo(minusButton.snp.trailing).offset(6)
make.trailing.equalTo(plusButton.snp.leading).offset(-6)
make.width.equalTo(90) // 최소 너비 보장
make.height.equalTo(35)
}

plusButton.snp.makeConstraints { make in
make.top.bottom.trailing.equalToSuperview()
make.width.equalTo(35) // 버튼 고정 너비
make.height.equalTo(35)
}
}

// MARK: - Actions
@objc private func didTapMinus() {
if currentValue > 0 {
currentValue -= 1
}
}

@objc private func didTapPlus() {
currentValue += 1
}
}

0 comments on commit 3667cb7

Please sign in to comment.