Skip to content

Commit

Permalink
[iOS#205] 카테고리 색상 선택 기능 및 수정 (#206)
Browse files Browse the repository at this point in the history
* refactor: Category 텍스트 필드로 수정

* refactor: 텍스트뷰에서 텍스트필드로 변경

* feat: colorWell로 색상 선택 기능 추가
  • Loading branch information
nemanjabenkovic authored Nov 27, 2023
1 parent 1deca01 commit df8f7f8
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 126 deletions.
12 changes: 8 additions & 4 deletions iOS/FlipMate/FlipMate.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
ED3595B72B0C887C00558FAA /* TimerFinishRequestDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED3595B62B0C887C00558FAA /* TimerFinishRequestDTO.swift */; };
ED3595B92B0C88A300558FAA /* TimerFinishResponseDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED3595B82B0C88A300558FAA /* TimerFinishResponseDTO.swift */; };
ED3595BD2B0DB29F00558FAA /* CategoryModifyViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED3595BC2B0DB29F00558FAA /* CategoryModifyViewController.swift */; };
ED3595BF2B0DB68200558FAA /* CategoryTitleTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED3595BE2B0DB68200558FAA /* CategoryTitleTextView.swift */; };
ED3595C12B0DC2F100558FAA /* CategoryColorSelectView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED3595C02B0DC2F100558FAA /* CategoryColorSelectView.swift */; };
ED38421B2B0F1B7E001E2803 /* GoogleAuthRequestDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED38421A2B0F1B7E001E2803 /* GoogleAuthRequestDTO.swift */; };
ED38421D2B0F1BE9001E2803 /* GoogleAuthEndpoints.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED38421C2B0F1BE9001E2803 /* GoogleAuthEndpoints.swift */; };
Expand All @@ -102,6 +101,8 @@
ED38422C2B0F4531001E2803 /* LoginViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED38422B2B0F4531001E2803 /* LoginViewModel.swift */; };
ED38422F2B0F747B001E2803 /* KeyChainManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED38422E2B0F747B001E2803 /* KeyChainManager.swift */; };
ED3842312B0F94E6001E2803 /* DefaultCategoryRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED3842302B0F94E6001E2803 /* DefaultCategoryRepository.swift */; };
ED82F0072B126C95005BB32D /* UITextField++Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED82F0062B126C95005BB32D /* UITextField++Extension.swift */; };
ED82F00B2B128C4D005BB32D /* UIColor++Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED82F00A2B128C4D005BB32D /* UIColor++Extension.swift */; };
ED9B2A7F2B06033F008FE1C5 /* Category.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED9B2A7E2B06033F008FE1C5 /* Category.swift */; };
ED9B2A812B06048D008FE1C5 /* CategoryViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED9B2A802B06048D008FE1C5 /* CategoryViewModel.swift */; };
EDC851C72B021492009031EA /* TabBarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDC851C62B021492009031EA /* TabBarViewController.swift */; };
Expand Down Expand Up @@ -220,7 +221,6 @@
ED3595B62B0C887C00558FAA /* TimerFinishRequestDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimerFinishRequestDTO.swift; sourceTree = "<group>"; };
ED3595B82B0C88A300558FAA /* TimerFinishResponseDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimerFinishResponseDTO.swift; sourceTree = "<group>"; };
ED3595BC2B0DB29F00558FAA /* CategoryModifyViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryModifyViewController.swift; sourceTree = "<group>"; };
ED3595BE2B0DB68200558FAA /* CategoryTitleTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryTitleTextView.swift; sourceTree = "<group>"; };
ED3595C02B0DC2F100558FAA /* CategoryColorSelectView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryColorSelectView.swift; sourceTree = "<group>"; };
ED38421A2B0F1B7E001E2803 /* GoogleAuthRequestDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GoogleAuthRequestDTO.swift; sourceTree = "<group>"; };
ED38421C2B0F1BE9001E2803 /* GoogleAuthEndpoints.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GoogleAuthEndpoints.swift; sourceTree = "<group>"; };
Expand All @@ -233,6 +233,8 @@
ED38422B2B0F4531001E2803 /* LoginViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewModel.swift; sourceTree = "<group>"; };
ED38422E2B0F747B001E2803 /* KeyChainManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyChainManager.swift; sourceTree = "<group>"; };
ED3842302B0F94E6001E2803 /* DefaultCategoryRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultCategoryRepository.swift; sourceTree = "<group>"; };
ED82F0062B126C95005BB32D /* UITextField++Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITextField++Extension.swift"; sourceTree = "<group>"; };
ED82F00A2B128C4D005BB32D /* UIColor++Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor++Extension.swift"; sourceTree = "<group>"; };
ED9B2A7E2B06033F008FE1C5 /* Category.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Category.swift; sourceTree = "<group>"; };
ED9B2A802B06048D008FE1C5 /* CategoryViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryViewModel.swift; sourceTree = "<group>"; };
EDC851C62B021492009031EA /* TabBarViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -321,6 +323,8 @@
isa = PBXGroup;
children = (
2C4D55AA2B033029006D7C26 /* UIView++Extension.swift */,
ED82F0062B126C95005BB32D /* UITextField++Extension.swift */,
ED82F00A2B128C4D005BB32D /* UIColor++Extension.swift */,
);
path = Extension;
sourceTree = "<group>";
Expand Down Expand Up @@ -852,7 +856,6 @@
children = (
EDC851D12B04EE83009031EA /* CategoryListCollectionViewCell.swift */,
2CE84EF82B0B8A0B00E2FB71 /* CategorySettingFooterView.swift */,
ED3595BE2B0DB68200558FAA /* CategoryTitleTextView.swift */,
ED3595C02B0DC2F100558FAA /* CategoryColorSelectView.swift */,
);
path = View;
Expand Down Expand Up @@ -1153,6 +1156,7 @@
2C801D802B04B68900A7ABAE /* TimerUseCase.swift in Sources */,
6086464E2B0DDA1300B0C1BC /* CategoryRepository.swift in Sources */,
2C2F21782B0F4CCC00B45BA8 /* StudyLog.swift in Sources */,
ED82F00B2B128C4D005BB32D /* UIColor++Extension.swift in Sources */,
2C88DCFE2B1244A6000B4686 /* LoginFlowCoordinator.swift in Sources */,
601773E42B021E6000D175D9 /* TimerViewController.swift in Sources */,
2C88DCF92B1242DA000B4686 /* TimerFlowCoordinator.swift in Sources */,
Expand All @@ -1169,7 +1173,6 @@
2C3430A72B0DD0F6008CBC85 /* TimerRepsoitory.swift in Sources */,
6057A58F2B0C801300EE58E8 /* NetworkError.swift in Sources */,
ED38422F2B0F747B001E2803 /* KeyChainManager.swift in Sources */,
ED3595BF2B0DB68200558FAA /* CategoryTitleTextView.swift in Sources */,
ED3842292B0F3B19001E2803 /* DefaultGoogleAuthRepository.swift in Sources */,
600908BE2AFCD7DF0065DFFB /* AppDelegate.swift in Sources */,
2CE84EFB2B0B92BA00E2FB71 /* UICollectionReusableView++Extension.swift in Sources */,
Expand All @@ -1178,6 +1181,7 @@
ED3595A92B0C7F3500558FAA /* HTTPMethod.swift in Sources */,
ED38421D2B0F1BE9001E2803 /* GoogleAuthEndpoints.swift in Sources */,
2C5CDA562B025426007AFC57 /* BaseViewController.swift in Sources */,
ED82F0072B126C95005BB32D /* UITextField++Extension.swift in Sources */,
2C3430992B0C8427008CBC85 /* Provider.swift in Sources */,
2C2F21702B0F429800B45BA8 /* StudyLogResponseDTO.swift in Sources */,
2C2F216E2B0F40A100B45BA8 /* DefaultStudyLogUseCase.swift in Sources */,
Expand Down
21 changes: 21 additions & 0 deletions iOS/FlipMate/FlipMate/Data/Extension/UIColor++Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// UIColor++Extension.swift
// FlipMate
//
// Created by 신민규 on 11/26/23.
//

import UIKit

extension UIColor {
func toHexString() -> String {
var red: CGFloat = 0
var green: CGFloat = 0
var blue: CGFloat = 0
var alpha: CGFloat = 0
getRed(&red, green: &green, blue: &blue, alpha: &alpha)
let rgb: Int = (Int)(red*255) << 16 | (Int)(green*255) << 8 | (Int)(blue*255) << 0

return String(format: "#%06x", rgb)
}
}
16 changes: 16 additions & 0 deletions iOS/FlipMate/FlipMate/Data/Extension/UITextField++Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// UITextField++Extension.swift
// FlipMate
//
// Created by 신민규 on 11/26/23.
//

import UIKit

extension UITextField {
func addLeftPadding(width: Int) {
let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: width, height: Int(self.frame.height)))
self.leftView = paddingView
self.leftViewMode = ViewMode.always
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ final class CategoryColorSelectView: UIView {
colorLabel.translatesAutoresizingMaskIntoConstraints = false
colorLabel.textColor = .label
colorLabel.font = FlipMateFont.mediumRegular.font
colorLabel.text = "# 000000"
colorLabel.text = "색상을 선택하세요"

return colorLabel
}()

private var colorCircle: UIImageView = {
let imageView = UIImageView()
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.image = UIImage(systemName: "circle.fill")

return imageView
private lazy var colorWell: UIColorWell = {
let colorWell = UIColorWell()
colorWell.translatesAutoresizingMaskIntoConstraints = false
colorWell.addTarget(self, action: #selector(colorWellChanged(_:)), for: .valueChanged)
return colorWell
}()

override init(frame: CGRect) {
Expand All @@ -39,13 +38,13 @@ final class CategoryColorSelectView: UIView {
private extension CategoryColorSelectView {
func configureUI() {
addSubview(colorLabel)
addSubview(colorCircle)
addSubview(colorWell)
self.backgroundColor = .systemBackground
NSLayoutConstraint.activate([
colorCircle.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -24.0),
colorCircle.centerYAnchor.constraint(equalTo: self.centerYAnchor),
colorCircle.widthAnchor.constraint(equalToConstant: 24.0),
colorCircle.heightAnchor.constraint(equalToConstant: 24.0)
colorWell.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -24.0),
colorWell.centerYAnchor.constraint(equalTo: self.centerYAnchor),
colorWell.widthAnchor.constraint(equalToConstant: 24.0),
colorWell.heightAnchor.constraint(equalToConstant: 24.0)
])

NSLayoutConstraint.activate([
Expand All @@ -55,6 +54,12 @@ private extension CategoryColorSelectView {
}
}

// MARK: - objc function
private extension CategoryColorSelectView {
@objc func colorWellChanged(_ sender: Any) {
colorLabel.text = colorWell.selectedColor?.toHexString()
}
}
@available(iOS 17.0, *)
#Preview {
CategoryColorSelectView()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@ final class CategoryModifyViewController: BaseViewController {
return label
}()

private lazy var categoryTitleTextView: CategoryTitleTextView = {
let textView = CategoryTitleTextView(placeholder: Constant.placeHolders[0])
textView.translatesAutoresizingMaskIntoConstraints = false
textView.layer.masksToBounds = true
textView.layer.cornerRadius = 6
textView.layer.borderColor = FlipMateColor.gray2.color?.cgColor
textView.layer.borderWidth = 1
private lazy var categoryTitleTextField: UITextField = {
let textField = UITextField()
textField.translatesAutoresizingMaskIntoConstraints = false
textField.delegate = self
textField.layer.masksToBounds = true
textField.layer.cornerRadius = 6
textField.layer.borderColor = FlipMateColor.gray2.color?.cgColor
textField.layer.borderWidth = 1
textField.clearButtonMode = .always

return textView
return textField
}()

private lazy var categoryColorSelectView: CategoryColorSelectView = {
Expand Down Expand Up @@ -99,9 +101,12 @@ final class CategoryModifyViewController: BaseViewController {
override func configureUI() {
view.backgroundColor = .systemBackground

categoryTitleTextField.placeholder = Constant.placeHolders[0]
categoryTitleTextField.addLeftPadding(width: 15)

let subViews = [
firstSectionTitleLabel,
categoryTitleTextView,
categoryTitleTextField,
secondSectionTitleLabel,
categoryColorSelectView
]
Expand All @@ -118,17 +123,18 @@ final class CategoryModifyViewController: BaseViewController {
])

NSLayoutConstraint.activate([
categoryTitleTextView.topAnchor.constraint(
categoryTitleTextField.topAnchor.constraint(
equalTo: firstSectionTitleLabel.bottomAnchor, constant: 12),
categoryTitleTextView.leadingAnchor.constraint(
categoryTitleTextField.leadingAnchor.constraint(
equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 30),
categoryTitleTextView.trailingAnchor.constraint(
equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -30)
categoryTitleTextField.trailingAnchor.constraint(
equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -30),
categoryTitleTextField.heightAnchor.constraint(equalToConstant: 40)
])

NSLayoutConstraint.activate([
secondSectionTitleLabel.topAnchor.constraint(
equalTo: categoryTitleTextView.bottomAnchor, constant: 60),
equalTo: categoryTitleTextField.bottomAnchor, constant: 60),
secondSectionTitleLabel.leftAnchor.constraint(
equalTo: view.safeAreaLayoutGuide.leftAnchor, constant: 32)
])
Expand All @@ -141,19 +147,24 @@ final class CategoryModifyViewController: BaseViewController {
categoryColorSelectView.trailingAnchor.constraint(
equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -30),
categoryColorSelectView.heightAnchor.constraint(
equalTo: categoryTitleTextView.heightAnchor)
equalTo: categoryTitleTextField.heightAnchor)
])

if purpose == .update {
guard let category = category else {
FMLogger.general.error("가져온 카테고리 없음 에러")
return
}
categoryTitleTextView.setText(text: category.subject)
setText(text: category.subject)
}
}
}

// MARK: UITextFieldDelegate
extension CategoryModifyViewController: UITextFieldDelegate {
func setText(text: String) {
categoryTitleTextField.text = text
}
}
// MARK: Navigation Bar
private extension CategoryModifyViewController {
func setUpNavigation() {
Expand Down Expand Up @@ -190,7 +201,7 @@ private extension CategoryModifyViewController {
if purpose == .create {
Task {
do {
guard let categoryTitle = categoryTitleTextView.text() else {
guard let categoryTitle = categoryTitleTextField.text else {
FMLogger.general.error("빈 제목, 추가할 수 없음")
return
}
Expand All @@ -203,7 +214,7 @@ private extension CategoryModifyViewController {
} else {
Task {
do {
guard let categoryTitle = categoryTitleTextView.text() else {
guard let categoryTitle = categoryTitleTextField.text else {
FMLogger.general.error("빈 제목, 추가할 수 없음")
return
}
Expand All @@ -220,3 +231,7 @@ private extension CategoryModifyViewController {
}
}
}
//@available(iOS 17.0, *)
//#Preview {
// CategoryModifyViewController(viewModel: CategoryViewModel(useCase: DefaultCategoryUseCase(repository: DefaultCategoryRepository(provider: Provider(urlSession: URLSession.shared)))), purpose: .create)
//}

0 comments on commit df8f7f8

Please sign in to comment.