Skip to content

Commit

Permalink
[FEAT][#36] 출석상태 버튼 구현
Browse files Browse the repository at this point in the history
- 출석 상태 enum 정의 (AttendanceStatus)
- 버튼 클릭 시 pickerView 얼럿 노출
- pickerView 선택 시 버튼 상태 갱신
  • Loading branch information
tngusmiso committed Feb 25, 2023
1 parent 987fb02 commit 7c057cd
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 4 deletions.
4 changes: 4 additions & 0 deletions momoIOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
3A75FC10298827BE00B36A46 /* MainAttendanceCodeCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A75FC0F298827BE00B36A46 /* MainAttendanceCodeCell.swift */; };
3A8BDEF329AA6D66005CF633 /* AttendanceListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A8BDEF229AA6D66005CF633 /* AttendanceListCell.swift */; };
3A8BDEF529AA7B74005CF633 /* MemberListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A8BDEF429AA7B74005CF633 /* MemberListCell.swift */; };
3A8BDEF729AA8144005CF633 /* AttendanceStatusButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A8BDEF629AA8144005CF633 /* AttendanceStatusButton.swift */; };
3A8E2DDF2997697E00D5476A /* AttendanceCodeDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A8E2DDE2997697E00D5476A /* AttendanceCodeDetailViewController.swift */; };
3A8FC29929A9EFEF000B9315 /* MemberManagementViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A8FC29829A9EFEF000B9315 /* MemberManagementViewController.swift */; };
3A8FC29D29A9F31D000B9315 /* MemberListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A8FC29C29A9F31D000B9315 /* MemberListViewController.swift */; };
Expand Down Expand Up @@ -79,6 +80,7 @@
3A75FC0F298827BE00B36A46 /* MainAttendanceCodeCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainAttendanceCodeCell.swift; sourceTree = "<group>"; };
3A8BDEF229AA6D66005CF633 /* AttendanceListCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttendanceListCell.swift; sourceTree = "<group>"; };
3A8BDEF429AA7B74005CF633 /* MemberListCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemberListCell.swift; sourceTree = "<group>"; };
3A8BDEF629AA8144005CF633 /* AttendanceStatusButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttendanceStatusButton.swift; sourceTree = "<group>"; };
3A8E2DDE2997697E00D5476A /* AttendanceCodeDetailViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttendanceCodeDetailViewController.swift; sourceTree = "<group>"; };
3A8FC29829A9EFEF000B9315 /* MemberManagementViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemberManagementViewController.swift; sourceTree = "<group>"; };
3A8FC29C29A9F31D000B9315 /* MemberListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemberListViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -324,6 +326,7 @@
3A8FC29829A9EFEF000B9315 /* MemberManagementViewController.swift */,
3A8FC29C29A9F31D000B9315 /* MemberListViewController.swift */,
3A8FC29E29A9F343000B9315 /* AttendanceListViewController.swift */,
3A8BDEF629AA8144005CF633 /* AttendanceStatusButton.swift */,
);
path = MemberManagement;
sourceTree = "<group>";
Expand Down Expand Up @@ -591,6 +594,7 @@
3AA713D1298946FF006F922F /* UIColor+Extension.swift in Sources */,
3A72A1FF29A9D59200F2716A /* CommonBottomAlert.swift in Sources */,
3AA713C929884007006F922F /* MainAttendanceDoneCell.swift in Sources */,
3A8BDEF729AA8144005CF633 /* AttendanceStatusButton.swift in Sources */,
BF405C8029976F9300B5889D /* CommonTextField.swift in Sources */,
BF43B57A29952AFF0026DCE3 /* MoimSettingCell.swift in Sources */,
E820792F298A138500B36FC9 /* MainSessionAbsentCell.swift in Sources */,
Expand Down
123 changes: 123 additions & 0 deletions momoIOS/AdminSide/MemberManagement/AttendanceStatusButton.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
//
// AttendanceStatusButton.swift
// momoIOS
//
// Created by 임수현 on 2023/02/26.
//

import UIKit

enum AttendanceStatus: CaseIterable {
/// 대기
case waiting
/// 정상출석
case attendance
/// 지각
case lateness
/// 통보결석
case noticedAbsence
/// 무단결석
case truancy

var title: String {
switch self {
case .waiting:
return "대기"
case .attendance:
return "정상출석"
case .lateness:
return "지각"
case .noticedAbsence:
return "통보결석"
case .truancy:
return "무단결석"
}
}

var color: UIColor {
switch self {
case .waiting:
return .pastbox
case .attendance:
return .attendanceCheck
case .lateness:
return .attendanceLate
case .noticedAbsence:
return .noticeAbsance
case .truancy:
return .warning
}
}
}

protocol AttendanceStatusButtonDelegate: AnyObject {
func didSelect(status: AttendanceStatus)
}

final class AttendanceStatusButton: UIButton {
weak var delegate: AttendanceStatusButtonDelegate?
private var pickerViewStatus: AttendanceStatus?

var name: String?
var status: AttendanceStatus = .waiting {
didSet {
self.setTitle(self.status.title, font: .tag2, color: .white)
self.configurate(bgColor: self.status.color, cornerRadius: 6, padding: 0)
}
}

override init(frame: CGRect) {
super.init(frame: frame)
self.addTarget(self, action: #selector(showPicker), for: .touchUpInside)
}

convenience init(status: AttendanceStatus) {
self.init(frame: .init(origin: .zero, size: .init(width: 57, height: 28)))
self.status = status
}

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

@objc private func showPicker() {
let alert = UIAlertController(title: self.name, message: "\n\n\n\n\n\n", preferredStyle: .alert)
let pickerView = UIPickerView(frame: .init(x: 0, y: 40, width: 270, height: 120))
pickerView.dataSource = self
pickerView.delegate = self

let cancelAction = UIAlertAction(title: "취소", style: .cancel) { [weak self] _ in
self?.pickerViewStatus = nil
}
let confirmAction = UIAlertAction(title: "확인", style: .default) { [weak self] _ in
guard let status = self?.pickerViewStatus else { return }
self?.delegate?.didSelect(status: status)
self?.pickerViewStatus = nil
}

alert.view.addSubview(pickerView)
alert.addAction(cancelAction)
alert.addAction(confirmAction)

UIApplication.topViewController()?.present(alert, animated: true)
}
}

extension AttendanceStatusButton: UIPickerViewDelegate {
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
self.pickerViewStatus = AttendanceStatus.allCases[safe: row]
}
}
extension AttendanceStatusButton: UIPickerViewDataSource {
func numberOfComponents(in pickerView: UIPickerView) -> Int {
1
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
AttendanceStatus.allCases.count
}

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
AttendanceStatus.allCases[safe: row]?.title
}
}
17 changes: 13 additions & 4 deletions momoIOS/AdminSide/MemberManagement/Cells/AttendanceListCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class AttendanceListCell: UITableViewCell {
private let nameLabel: UILabel = UILabel()
private let generationLabel: UILabel = UILabel()
private let jobLabel: UILabel = UILabel()
private let attendanceStatusButton: UIButton = UIButton()
private let attendanceStatusButton: AttendanceStatusButton = AttendanceStatusButton()

// MARK: - Initializer
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
Expand All @@ -31,7 +31,8 @@ final class AttendanceListCell: UITableViewCell {

// MARK: - Setup
private func setupViews() {
self.nameLabel.text = "홍길동"
let name = ["문다연", "임수현", "조수연"].randomElement() ?? "홍길동"
self.nameLabel.text = name
self.nameLabel.font = .body16
self.nameLabel.textColor = .gray800

Expand All @@ -43,8 +44,10 @@ final class AttendanceListCell: UITableViewCell {
self.jobLabel.font = .body16
self.jobLabel.textColor = .gray800

self.attendanceStatusButton.setTitle("정상출석", font: .tag2, color: .white)
self.attendanceStatusButton.configurate(bgColor: .attendanceCheck, cornerRadius: 6, padding: 0)
let status = [AttendanceStatus](arrayLiteral: .waiting, .attendance, .lateness, .noticedAbsence, .truancy).randomElement() ?? .waiting
self.attendanceStatusButton.name = name
self.attendanceStatusButton.status = status
self.attendanceStatusButton.delegate = self
}

// MARK: - Layout
Expand Down Expand Up @@ -82,3 +85,9 @@ final class AttendanceListCell: UITableViewCell {
}
}
}

extension AttendanceListCell: AttendanceStatusButtonDelegate {
func didSelect(status: AttendanceStatus) {
self.attendanceStatusButton.status = status
}
}

0 comments on commit 7c057cd

Please sign in to comment.