diff --git a/HMH_iOS/HMH_iOS.xcodeproj/project.pbxproj b/HMH_iOS/HMH_iOS.xcodeproj/project.pbxproj index 9fa3802..94d63b0 100644 --- a/HMH_iOS/HMH_iOS.xcodeproj/project.pbxproj +++ b/HMH_iOS/HMH_iOS.xcodeproj/project.pbxproj @@ -9,6 +9,8 @@ /* Begin PBXBuildFile section */ 0B0035402B43D64D00DA140C /* HMHNavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B00353F2B43D64D00DA140C /* HMHNavigationBar.swift */; }; 0B2C2D3B2B443BE90023CCFA /* Image.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B2C2D3A2B443BE90023CCFA /* Image.swift */; }; + 0B2C2D3F2B4559E10023CCFA /* OnboardingButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B2C2D3E2B4559E10023CCFA /* OnboardingButton.swift */; }; + 0B2C2D412B4572240023CCFA /* HMHSelectButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B2C2D402B4572240023CCFA /* HMHSelectButton.swift */; }; 0B50F9CB2B369813000C5046 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B50F9CA2B369813000C5046 /* AppDelegate.swift */; }; 0B50F9CD2B369813000C5046 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B50F9CC2B369813000C5046 /* SceneDelegate.swift */; }; 0B50F9CF2B369813000C5046 /* HomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B50F9CE2B369813000C5046 /* HomeViewController.swift */; }; @@ -60,6 +62,8 @@ /* Begin PBXFileReference section */ 0B00353F2B43D64D00DA140C /* HMHNavigationBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HMHNavigationBar.swift; sourceTree = ""; }; 0B2C2D3A2B443BE90023CCFA /* Image.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Image.swift; sourceTree = ""; }; + 0B2C2D3E2B4559E10023CCFA /* OnboardingButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingButton.swift; sourceTree = ""; }; + 0B2C2D402B4572240023CCFA /* HMHSelectButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HMHSelectButton.swift; sourceTree = ""; }; 0B50F9C72B369813000C5046 /* HMH_iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HMH_iOS.app; sourceTree = BUILT_PRODUCTS_DIR; }; 0B50F9CA2B369813000C5046 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 0B50F9CC2B369813000C5046 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; @@ -121,6 +125,22 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 0B2C2D3C2B4559AE0023CCFA /* Onboarding */ = { + isa = PBXGroup; + children = ( + 0B2C2D3D2B4559C90023CCFA /* Views */, + ); + path = Onboarding; + sourceTree = ""; + }; + 0B2C2D3D2B4559C90023CCFA /* Views */ = { + isa = PBXGroup; + children = ( + 0B2C2D3E2B4559E10023CCFA /* OnboardingButton.swift */, + ); + path = Views; + sourceTree = ""; + }; 0B50F9BE2B369813000C5046 = { isa = PBXGroup; children = ( @@ -184,6 +204,7 @@ 0B67CCE72B369BE300582D54 /* Presentation */ = { isa = PBXGroup; children = ( + 0B2C2D3C2B4559AE0023CCFA /* Onboarding */, 0B8A89A72B369DE600688BA6 /* Home */, 0B8A89A52B369DD500688BA6 /* Common */, ); @@ -315,6 +336,7 @@ isa = PBXGroup; children = ( 0B00353F2B43D64D00DA140C /* HMHNavigationBar.swift */, + 0B2C2D402B4572240023CCFA /* HMHSelectButton.swift */, ); path = UIComponets; sourceTree = ""; @@ -464,6 +486,7 @@ buildActionMask = 2147483647; files = ( 0B50F9CF2B369813000C5046 /* HomeViewController.swift in Sources */, + 0B2C2D412B4572240023CCFA /* HMHSelectButton.swift in Sources */, 0B8A89BC2B369F2D00688BA6 /* UIView+.swift in Sources */, 0B8A89AF2B369E4300688BA6 /* HomeModel.swift in Sources */, 36A3D9C02B409CBD007EA272 /* Font.swift in Sources */, @@ -472,6 +495,7 @@ 0B50F9CB2B369813000C5046 /* AppDelegate.swift in Sources */, 0B8A89C42B369FA000688BA6 /* F.swift in Sources */, 0B8A89B72B369F1100688BA6 /* C.swift in Sources */, + 0B2C2D3F2B4559E10023CCFA /* OnboardingButton.swift in Sources */, 0B2C2D3B2B443BE90023CCFA /* Image.swift in Sources */, 0B8A89AD2B369E3B00688BA6 /* HomeCell.swift in Sources */, 0B8A89C62B369FA800688BA6 /* H.swift in Sources */, diff --git a/HMH_iOS/HMH_iOS/Presentation/Common/UIComponets/HMHSelectButton.swift b/HMH_iOS/HMH_iOS/Presentation/Common/UIComponets/HMHSelectButton.swift new file mode 100644 index 0000000..77a1772 --- /dev/null +++ b/HMH_iOS/HMH_iOS/Presentation/Common/UIComponets/HMHSelectButton.swift @@ -0,0 +1,117 @@ +// +// HMHSelectButton.swift +// HMH_iOS +// +// Created by Seonwoo Kim on 1/3/24. +// + +import UIKit + +import SnapKit +import Then + +final class HMHSelectButton: UIButton { + @frozen + enum HMHSelectButtonType { + case solitary + case multiple + case disabled + } + + private var selectButtonType: HMHSelectButtonType = .disabled + private var isChecked: Bool = false + + private let buttonContentLabel = UILabel().then { + $0.font = UIFont.iosText5Medium16 + } + + init(buttonType: HMHSelectButtonType, buttonText: String) { + super.init(frame: .zero) + self.selectButtonType = buttonType + buttonContentLabel.text = buttonText + + configureButton() + addTarget() + setUI() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + private func setUI() { + setHierarchy() + setConstraints() + } + + private func setHierarchy() { + self.addSubview(buttonContentLabel) + } + + private func setConstraints() { + self.snp.makeConstraints { + $0.height.equalTo(62.adjusted) + } + + buttonContentLabel.snp.makeConstraints { + $0.center.equalToSuperview() + } + } + + private func addTarget() { + self.addTarget(self, action: #selector(onboardingButtonTapped), for: .touchUpInside) + } + + private func configureButton() { + self.makeCornerRound(radius: 6.adjustedHeight) + self.layer.cornerCurve = .continuous + + switch selectButtonType { + case .solitary,.multiple: + self.isEnabled = true + self.backgroundColor = .gray6 + buttonContentLabel.textColor = .whiteText + + case .disabled: + self.isEnabled = false + self.backgroundColor = .gray7 + buttonContentLabel.textColor = .gray4 + } + } + + private func updateStyle() { + if isChecked { + backgroundColor = .bluePurpleActive + makeBorder(width: 1.5, color: .bluePurpleLine) + } else { + backgroundColor = .gray6 + layer.borderColor = UIColor.clear.cgColor + } + } + + private func setChecked(_ checked: Bool) { + isChecked = checked + updateStyle() + } + + @objc private func onboardingButtonTapped() { + switch selectButtonType { + case .solitary: + guard !isChecked else { return } + + superview?.subviews.forEach { subview in + if let button = subview as? HMHSelectButton, button != self { + button.setChecked(false) + } + } + + setChecked(true) + + case .multiple: + setChecked(!isChecked) + + case .disabled: + return + } + } +} diff --git a/HMH_iOS/HMH_iOS/Presentation/Onboarding/Views/OnboardingButton.swift b/HMH_iOS/HMH_iOS/Presentation/Onboarding/Views/OnboardingButton.swift new file mode 100644 index 0000000..5027810 --- /dev/null +++ b/HMH_iOS/HMH_iOS/Presentation/Onboarding/Views/OnboardingButton.swift @@ -0,0 +1,73 @@ +// +// OnboardingButton.swift +// HMH_iOS +// +// Created by Seonwoo Kim on 1/3/24. +// + +import UIKit + +import SnapKit +import Then + +final class OnboardingButton: UIButton { + @frozen + enum OnboardingButtonType { + case enabled + case disabled + } + + private var type: OnboardingButtonType = .disabled + + private let buttonTitleLabel = UILabel().then { + $0.textColor = .whiteText + $0.font = .iosText4Semibold16 + } + + init(buttonStatus type: OnboardingButtonType, buttonText: String) { + super.init(frame: .zero) + self.type = type + buttonTitleLabel.text = buttonText + + configureButton() + setUI() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + private func setUI() { + setHierarchy() + setConstraints() + } + + private func setHierarchy() { + self.addSubview(buttonTitleLabel) + } + + private func setConstraints() { + self.snp.makeConstraints { + $0.height.equalTo(52.adjusted) + } + + buttonTitleLabel.snp.makeConstraints { + $0.center.equalToSuperview() + } + } + + private func configureButton() { + self.makeCornerRound(radius: 6.adjustedHeight) + self.layer.cornerCurve = .continuous + + switch type { + case .enabled: + self.isEnabled = true + self.backgroundColor = .bluePurpleButton + + case .disabled: + self.isEnabled = false + self.backgroundColor = .gray5 + } + } +}