Skip to content

Commit

Permalink
Merge pull request #23 from Noostak/feat/NST-52/scheduleCategoryBtn
Browse files Browse the repository at this point in the history
[Feat/NST-52] #20 - 일정 카테고리 버튼
  • Loading branch information
oyslucy authored Jan 10, 2025
2 parents e47e4fd + b7e89b4 commit 4b30dcb
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 4 deletions.
18 changes: 16 additions & 2 deletions Noostak_iOS/Noostak_iOS/Domain/Entity/Schedule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// Created by 오연서 on 1/5/25.
//

import Foundation
import UIKit

enum ScheduleCategory: String {
enum ScheduleCategory: String, CaseIterable {
case important
case schedule
case hobby
Expand Down Expand Up @@ -62,4 +62,18 @@ extension ScheduleCategory {
return "기타"
}
}

/// 색상 반환
var displayColor: UIColor {
switch self {
case .important:
return .appOrange
case .schedule:
return .appBlue
case .hobby:
return .appPurple
case .other:
return .appMint
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ final class MemberAvailabilityChip: UIView {
private func setUpUI() {

self.do {
$0.layer.cornerRadius = 16
$0.layer.cornerRadius = 15
$0.layer.borderWidth = 1

switch status {
Expand All @@ -69,7 +69,7 @@ final class MemberAvailabilityChip: UIView {
private func setUpLayout() {
self.snp.makeConstraints {
if status == .myself {
$0.width.equalTo(28)
$0.width.equalTo(39)
}
$0.height.equalTo(30)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//
// ScheduleCategoryButton.swift
// Noostak_iOS
//
// Created by 오연서 on 1/8/25.
//

import UIKit
import RxSwift
import RxCocoa

final class ScheduleCategoryButton: UIButton {
// MARK: Properties
private var category: ScheduleCategory?
private var categoryButtonType: ButtonType = .Input
private let disposeBag = DisposeBag()
private let isSelectedSubject = BehaviorRelay<Bool>(value: false)

// MARK: Init
init(category: ScheduleCategory, buttonType: ButtonType) {
super.init(frame: .zero)
self.category = category
self.categoryButtonType = buttonType
self.setTitle(category.name, for: .normal)
setUpUI()
setUpLayout()
}

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

private func setUpUI() {
switch categoryButtonType {
case .Input:
/// 입력 모드: 선택 여부에 따라 색상 변경
self.titleLabel?.font = .PretendardStyle.b4_sb.font
self.layer.borderWidth = 1
self.layer.cornerRadius = 18.5
bindUI()
case .ReadOnly:
/// 표시 모드: 컬러 칩 스타일
guard let category = category else { return }
self.isUserInteractionEnabled = false
self.backgroundColor = category.displayColor
self.setTitleColor(category == .other ? .appGray800 : .appWhite, for: .normal)
self.layer.borderColor = UIColor.appWhite.cgColor
self.titleLabel?.font = .PretendardStyle.c2_sb.font
self.layer.borderWidth = 1
self.layer.cornerRadius = 15
}
}

private func setUpLayout() {
self.snp.makeConstraints {
switch categoryButtonType {
case .Input:
$0.height.equalTo(37)
$0.width.equalTo(66)
case .ReadOnly:
$0.height.equalTo(30)
$0.width.equalTo(53)
}
}
}

private func bindUI() {
isSelectedSubject
.distinctUntilChanged()
.subscribe(onNext: { [weak self] isSelected in
guard let self = self else { return }
self.backgroundColor = isSelected ? .appBlack : .appWhite
self.layer.borderColor = isSelected ? UIColor.appBlack.cgColor : UIColor.appGray200.cgColor
self.setTitleColor(isSelected ? .appWhite : .appBlack, for: .normal)
})
.disposed(by: disposeBag)
}
}

extension ScheduleCategoryButton {
enum ButtonType {
case Input
case ReadOnly
}
}

0 comments on commit 4b30dcb

Please sign in to comment.