diff --git a/HealthFoodMe/HealthFoodMe.xcodeproj/project.pbxproj b/HealthFoodMe/HealthFoodMe.xcodeproj/project.pbxproj index e05281e6..b7bb7ff9 100644 --- a/HealthFoodMe/HealthFoodMe.xcodeproj/project.pbxproj +++ b/HealthFoodMe/HealthFoodMe.xcodeproj/project.pbxproj @@ -47,6 +47,11 @@ A93252B7287F3272001EDF50 /* Scrap.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A93252B6287F3272001EDF50 /* Scrap.storyboard */; }; A93252BA287F3E73001EDF50 /* ScrapEmptyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A93252B9287F3E73001EDF50 /* ScrapEmptyView.swift */; }; A93252BD287F52E4001EDF50 /* ScrapDataModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A93252BC287F52E4001EDF50 /* ScrapDataModel.swift */; }; + A93252C628808B82001EDF50 /* ReviewDeleteAlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A93252C528808B82001EDF50 /* ReviewDeleteAlertView.swift */; }; + A93252CD28808BE2001EDF50 /* LogoutAlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A93252CC28808BE2001EDF50 /* LogoutAlertView.swift */; }; + A93252CF2880913F001EDF50 /* HelfmeAlertVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A93252CE2880913F001EDF50 /* HelfmeAlertVC.swift */; }; + A93252D428809BBC001EDF50 /* WithdrawalAlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A93252D328809BBC001EDF50 /* WithdrawalAlertView.swift */; }; + A93252E22880CBB9001EDF50 /* HelfmeAlert.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A93252E12880CBB9001EDF50 /* HelfmeAlert.storyboard */; }; A938BB8E287D221200B8DE07 /* Search.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A938BB8D287D221200B8DE07 /* Search.storyboard */; }; A938BB90287D222800B8DE07 /* MainDetail.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A938BB8F287D222800B8DE07 /* MainDetail.storyboard */; }; A9525F712873E1750065EB1D /* SearchVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9525F702873E1750065EB1D /* SearchVC.swift */; }; @@ -208,6 +213,11 @@ A93252B6287F3272001EDF50 /* Scrap.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Scrap.storyboard; sourceTree = ""; }; A93252B9287F3E73001EDF50 /* ScrapEmptyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrapEmptyView.swift; sourceTree = ""; }; A93252BC287F52E4001EDF50 /* ScrapDataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrapDataModel.swift; sourceTree = ""; }; + A93252C528808B82001EDF50 /* ReviewDeleteAlertView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReviewDeleteAlertView.swift; sourceTree = ""; }; + A93252CC28808BE2001EDF50 /* LogoutAlertView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogoutAlertView.swift; sourceTree = ""; }; + A93252CE2880913F001EDF50 /* HelfmeAlertVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HelfmeAlertVC.swift; sourceTree = ""; }; + A93252D328809BBC001EDF50 /* WithdrawalAlertView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WithdrawalAlertView.swift; sourceTree = ""; }; + A93252E12880CBB9001EDF50 /* HelfmeAlert.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = HelfmeAlert.storyboard; sourceTree = ""; }; A938BB8D287D221200B8DE07 /* Search.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Search.storyboard; sourceTree = ""; }; A938BB8F287D222800B8DE07 /* MainDetail.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = MainDetail.storyboard; sourceTree = ""; }; A9525F702873E1750065EB1D /* SearchVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchVC.swift; sourceTree = ""; }; @@ -580,6 +590,34 @@ path = Model; sourceTree = ""; }; + A93252BE288086BA001EDF50 /* HelpmeAlerts */ = { + isa = PBXGroup; + children = ( + A93252D72880B13A001EDF50 /* VC */, + A93252D028809144001EDF50 /* Views */, + ); + path = HelpmeAlerts; + sourceTree = ""; + }; + A93252D028809144001EDF50 /* Views */ = { + isa = PBXGroup; + children = ( + A93252CC28808BE2001EDF50 /* LogoutAlertView.swift */, + A93252C528808B82001EDF50 /* ReviewDeleteAlertView.swift */, + A93252D328809BBC001EDF50 /* WithdrawalAlertView.swift */, + ); + path = Views; + sourceTree = ""; + }; + A93252D72880B13A001EDF50 /* VC */ = { + isa = PBXGroup; + children = ( + A93252CE2880913F001EDF50 /* HelfmeAlertVC.swift */, + A93252E12880CBB9001EDF50 /* HelfmeAlert.storyboard */, + ); + path = VC; + sourceTree = ""; + }; A9525F6A2873DCD30065EB1D /* SearchScene */ = { isa = PBXGroup; children = ( @@ -1182,6 +1220,7 @@ EBF66A9F287227F500DE0ED1 /* Common */ = { isa = PBXGroup; children = ( + A93252BE288086BA001EDF50 /* HelpmeAlerts */, EB033E82287B5B6E00C48FB9 /* UI Components */, EBF66AA0287227F500DE0ED1 /* Base */, ); @@ -1427,6 +1466,7 @@ 3B089C4B287D877F00DA80B9 /* GodoB.otf in Resources */, A938BB90287D222800B8DE07 /* MainDetail.storyboard in Resources */, 695758BD287DA4CD00E36789 /* ReviewWrite.storyboard in Resources */, + A93252E22880CBB9001EDF50 /* HelfmeAlert.storyboard in Resources */, 3BCC442028745FE500661A12 /* SocialLogin.storyboard in Resources */, 3B089C4A287D877B00DA80B9 /* GodoB.ttf in Resources */, 3B0B25562876BBE400950539 /* Pretendard-Regular.otf in Resources */, @@ -1538,6 +1578,7 @@ EBF66AE4287227F500DE0ED1 /* HeaderType.swift in Sources */, FD58291A287DC39A00CE62E8 /* mapContainerViewDelegateProxy.swift in Sources */, EBF66ADB287227F500DE0ED1 /* LaunchInstructor.swift in Sources */, + A93252D428809BBC001EDF50 /* WithdrawalAlertView.swift in Sources */, EBF66B01287227F500DE0ED1 /* PostDetail.swift in Sources */, EBF66ABC287227F500DE0ED1 /* UserDefaults+.swift in Sources */, 695758C3287DF04400E36789 /* AddPhotoCVC.swift in Sources */, @@ -1558,8 +1599,10 @@ EB6A44D228737CC400749582 /* MainDetailRepository.swift in Sources */, FDC1028B2880B133001F0125 /* CTAButton.swift in Sources */, EBF66B0C2872B4FE00DE0ED1 /* StoryboardLiterals.swift in Sources */, + A93252CD28808BE2001EDF50 /* LogoutAlertView.swift in Sources */, EBF66AF7287227F500DE0ED1 /* manageObserverAction.swift in Sources */, EBF66B05287227F500DE0ED1 /* GeneralResponse.swift in Sources */, + A93252CF2880913F001EDF50 /* HelfmeAlertVC.swift in Sources */, EBF66AC1287227F500DE0ED1 /* UIStackView+.swift in Sources */, EBF66AF1287227F500DE0ED1 /* ShowToast.swift in Sources */, EBF66AC4287227F500DE0ED1 /* UIButton+.swift in Sources */, @@ -1602,6 +1645,7 @@ EBF66AFD287227F500DE0ED1 /* calculateTopInset.swift in Sources */, EBF66ADE287227F500DE0ED1 /* HomeRouter.swift in Sources */, EBF66ACF287227F500DE0ED1 /* Result+.swift in Sources */, + A93252C628808B82001EDF50 /* ReviewDeleteAlertView.swift in Sources */, EBF66AD7287227F500DE0ED1 /* Presentable.swift in Sources */, A932527E287DD261001EDF50 /* SearchResultVC.swift in Sources */, EBD19275287F256000EA053E /* EncodeURLKorean.swift in Sources */, diff --git a/HealthFoodMe/HealthFoodMe/Application/ModuleFactory/Factory/ModuleFactory.swift b/HealthFoodMe/HealthFoodMe/Application/ModuleFactory/Factory/ModuleFactory.swift index 669d6d8b..3ba44ad0 100644 --- a/HealthFoodMe/HealthFoodMe/Application/ModuleFactory/Factory/ModuleFactory.swift +++ b/HealthFoodMe/HealthFoodMe/Application/ModuleFactory/Factory/ModuleFactory.swift @@ -99,6 +99,13 @@ class ModuleFactory: ModuleFactoryProtocol { return vc } + + // MARK: - HelfmeAlert + func makeHelfmeAlertVC() -> HelfmeAlertVC { + let vc = HelfmeAlertVC.controllerFromStoryboard(.helfmeAlert) + + return vc + } // MARK: - Plan diff --git a/HealthFoodMe/HealthFoodMe/Global/Extension/UI/UIViewController+.swift b/HealthFoodMe/HealthFoodMe/Global/Extension/UI/UIViewController+.swift index 67de8e8b..dd6f9eb9 100644 --- a/HealthFoodMe/HealthFoodMe/Global/Extension/UI/UIViewController+.swift +++ b/HealthFoodMe/HealthFoodMe/Global/Extension/UI/UIViewController+.swift @@ -24,4 +24,24 @@ extension UIViewController { func dismissKeyboard() { view.endEditing(true) } + + func makeAlert(alertType: AlertType = .logoutAlert, + title: String?, + subtitle: String?, + okAction: (() -> Void)? ) { + + let alertVC = ModuleFactory.resolve().makeHelfmeAlertVC() + + alertVC.alertType = alertType + if let title = title { + alertVC.alertTitle = title + } + if let subtitle = subtitle { + alertVC.alertContent = subtitle + } + alertVC.okAction = okAction + alertVC.modalTransitionStyle = .crossDissolve + alertVC.modalPresentationStyle = .overCurrentContext + present(alertVC, animated: true) + } } diff --git a/HealthFoodMe/HealthFoodMe/Global/Literals/StoryboardLiterals.swift b/HealthFoodMe/HealthFoodMe/Global/Literals/StoryboardLiterals.swift index 9c99013b..63ebc7bc 100644 --- a/HealthFoodMe/HealthFoodMe/Global/Literals/StoryboardLiterals.swift +++ b/HealthFoodMe/HealthFoodMe/Global/Literals/StoryboardLiterals.swift @@ -21,6 +21,7 @@ enum Storyboards: String { case search = "Search" case searchResult = "SearchResult" case scrap = "Scrap" + case helfmeAlert = "HelfmeAlert" case menuTab = "MenuTab" case reviewWrite = "ReviewWrite" diff --git a/HealthFoodMe/HealthFoodMe/Global/Literals/StringLiterals.swift b/HealthFoodMe/HealthFoodMe/Global/Literals/StringLiterals.swift index 329b6ce5..5b4e8040 100644 --- a/HealthFoodMe/HealthFoodMe/Global/Literals/StringLiterals.swift +++ b/HealthFoodMe/HealthFoodMe/Global/Literals/StringLiterals.swift @@ -81,4 +81,29 @@ struct I18N { static let dietStore = "다이어터도 즐길 수 있는 식당" static let goScrap = "스크랩하러 가기" } + + struct HelfmeAlert { + static let logout = "정말 로그아웃 하시겠어요?" + static let logoutContent = + """ + 로그아웃 시 헬푸미의 업데이트 내용을 + 보실 수 없습니다. + """ + static let yes = "네" + static let no = "아니요" + + static let reviewDelete = + """ + 작성한 리뷰를 + 삭제하실 건가요? + """ + + static let withdrawal = "정말로 탈퇴하실건가요?" + static let withdrawalContent = + """ + 탈퇴 시 헬푸미의 새로운 정보를 + 얻을 수 없습니다. + """ + static let withdrawalYes = "네 탈퇴할게요" + } } diff --git a/HealthFoodMe/HealthFoodMe/Presentation/Common/HelpmeAlerts/VC/HelfmeAlert.storyboard b/HealthFoodMe/HealthFoodMe/Presentation/Common/HelpmeAlerts/VC/HelfmeAlert.storyboard new file mode 100644 index 00000000..98ba4d84 --- /dev/null +++ b/HealthFoodMe/HealthFoodMe/Presentation/Common/HelpmeAlerts/VC/HelfmeAlert.storyboard @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/HealthFoodMe/HealthFoodMe/Presentation/Common/HelpmeAlerts/VC/HelfmeAlertVC.swift b/HealthFoodMe/HealthFoodMe/Presentation/Common/HelpmeAlerts/VC/HelfmeAlertVC.swift new file mode 100644 index 00000000..298c46c8 --- /dev/null +++ b/HealthFoodMe/HealthFoodMe/Presentation/Common/HelpmeAlerts/VC/HelfmeAlertVC.swift @@ -0,0 +1,138 @@ +// +// HelfmeAlertVC.swift +// HealthFoodMe +// +// Created by 김영인 on 2022/07/15. +// + +import UIKit + +import SnapKit + +enum AlertType { + case logoutAlert + case deleteReviewAlert + case withdrawalAlert +} + +final class HelfmeAlertVC: UIViewController { + + // MARK: - Properties + + let width = UIScreen.main.bounds.width + var alertType: AlertType = .logoutAlert + var alertTitle: String? + var alertContent: String? + var okAction: (() -> Void)? + + // MARK: - UI Components + + private let logoutAlertView: LogoutAlertView = { + let view = LogoutAlertView() + view.layer.cornerRadius = 15 + return view + }() + + private let reviewDeleteAlertView: ReviewDeleteAlertView = { + let view = ReviewDeleteAlertView() + view.layer.cornerRadius = 15 + return view + }() + + private let withdrawalAlertView: WithdrawalAlertView = { + let view = WithdrawalAlertView() + view.layer.cornerRadius = 15 + return view + }() + + // MARK: - View Life Cycle + + override func viewDidLoad() { + super.viewDidLoad() + setAlert() + setUI() + setLayout() + setDelegate() + } +} + +// MARK: - Methods + +extension HelfmeAlertVC { + private func setAlert() { + switch alertType { + case .logoutAlert: + logoutAlertView.setData(title: alertTitle, subtitle: alertContent) + setAlertView(logout: false, deleteReview: true, withdrawal: true) + case .deleteReviewAlert: + reviewDeleteAlertView.setData(title: alertTitle) + setAlertView(logout: true, deleteReview: false, withdrawal: true) + case .withdrawalAlert: + withdrawalAlertView.setData(title: alertTitle, subtitle: alertContent) + setAlertView(logout: true, deleteReview: true, withdrawal: false) + } + } + + private func setAlertView(logout: Bool, deleteReview: Bool, withdrawal: Bool) { + logoutAlertView.isHidden = logout + reviewDeleteAlertView.isHidden = deleteReview + withdrawalAlertView.isHidden = withdrawal + } + + private func setUI() { + view.backgroundColor = .black.withAlphaComponent(0.4) + } + + private func setLayout() { + view.addSubviews(logoutAlertView, + reviewDeleteAlertView, + withdrawalAlertView) + + view.addSubviews(withdrawalAlertView) + + logoutAlertView.snp.makeConstraints { + let logoutWidth = width * (288/375) + $0.center.equalToSuperview() + $0.width.equalTo(logoutWidth) + $0.height.equalTo(logoutWidth * (241/288)) + } + + reviewDeleteAlertView.snp.makeConstraints { + let reviewDeleteWidth = width * (288/375) + $0.center.equalToSuperview() + $0.width.equalTo(reviewDeleteWidth) + $0.height.equalTo(reviewDeleteWidth * (223/288)) + } + + withdrawalAlertView.snp.makeConstraints { + let withdrawalWidth = width * (288/375) + $0.center.equalToSuperview() + $0.width.equalTo(withdrawalWidth) + $0.height.equalTo(withdrawalWidth * (222/288)) + } + } + + private func setDelegate() { + logoutAlertView.delegate = self + reviewDeleteAlertView.delegate = self + withdrawalAlertView.delegate = self + } + + private func emptyActions() { + + } +} + +// MARK: - AlertDelegate + +extension HelfmeAlertVC: AlertDelegate { + func alertDidTap() { + dismiss(animated: false) { + (self.okAction ?? self.emptyActions)() + } + } + + func alertDismiss() { + dismiss(animated: true) + } +} diff --git a/HealthFoodMe/HealthFoodMe/Presentation/Common/HelpmeAlerts/Views/LogoutAlertView.swift b/HealthFoodMe/HealthFoodMe/Presentation/Common/HelpmeAlerts/Views/LogoutAlertView.swift new file mode 100644 index 00000000..f6eb869e --- /dev/null +++ b/HealthFoodMe/HealthFoodMe/Presentation/Common/HelpmeAlerts/Views/LogoutAlertView.swift @@ -0,0 +1,132 @@ +// +// LogoutAlertView.swift +// HealthFoodMe +// +// Created by 김영인 on 2022/07/15. +// + +import UIKit + +import SnapKit + +protocol AlertDelegate: AnyObject { + func alertDidTap() + func alertDismiss() +} + +final class LogoutAlertView: UIView { + + // MARK: - Properties + + let width = UIScreen.main.bounds.width + weak var delegate: AlertDelegate? + + // MARK: - UI Components + + private var titleLabel: UILabel = { + let lb = UILabel() + lb.textColor = .helfmeBlack + lb.font = .NotoMedium(size: 16) + return lb + }() + + private var subtitleLabel: UILabel = { + let lb = UILabel() + lb.textColor = .helfmeBlack + lb.font = .NotoRegular(size: 12) + lb.numberOfLines = 0 + lb.textAlignment = .center + return lb + }() + + private lazy var firstButton: UIButton = { + let btn = UIButton() + btn.backgroundColor = .mainRed + btn.setTitleColor(UIColor.helfmeWhite, for: .normal) + btn.setTitle(I18N.HelfmeAlert.yes, for: .normal) + btn.titleLabel?.font = .NotoBold(size: 15) + btn.layer.cornerRadius = 8 + btn.addTarget(self, action: #selector(didTapLogout), for: .touchUpInside) + return btn + }() + + private lazy var secondButton: UIButton = { + let btn = UIButton() + btn.backgroundColor = .helfmeWhite + btn.setTitleColor(UIColor.helfmeGray1, for: .normal) + btn.setTitle(I18N.HelfmeAlert.no, for: .normal) + btn.titleLabel?.textColor = .helfmeGray1 + btn.titleLabel?.font = .NotoBold(size: 15) + btn.layer.cornerRadius = 8 + btn.layer.borderColor = UIColor.helfmeLineGray.cgColor + btn.addTarget(self, action: #selector(didTapClose), for: .touchUpInside) + btn.layer.borderWidth = 1 + return btn + }() + + // MARK: - View Life Cycle + + override init(frame: CGRect) { + super.init(frame: frame) + setUI() + setLayout() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} + +// MARK: - @objc Methods + +extension LogoutAlertView { + @objc func didTapLogout() { + delegate?.alertDidTap() + } + + @objc func didTapClose() { + delegate?.alertDismiss() + } +} + +// MARK: - Methods + +extension LogoutAlertView { + func setData(title: String?, subtitle: String?) { + titleLabel.text = title + subtitleLabel.text = subtitle + } + + private func setUI() { + backgroundColor = .helfmeWhite + } + + private func setLayout() { + addSubviews(titleLabel, + subtitleLabel, + firstButton, + secondButton) + + titleLabel.snp.makeConstraints { + $0.top.equalTo(safeAreaLayoutGuide).offset(32) + $0.centerX.equalTo(safeAreaLayoutGuide) + } + + subtitleLabel.snp.makeConstraints { + $0.top.equalTo(titleLabel.snp.bottom).offset(8) + $0.leading.trailing.equalTo(safeAreaLayoutGuide).inset(width * (50/375)) + } + + firstButton.snp.makeConstraints { + $0.top.equalTo(subtitleLabel.snp.bottom).offset(24) + $0.leading.trailing.equalTo(safeAreaLayoutGuide).inset(width * (20/375)) + $0.height.equalTo(44) + } + + secondButton.snp.makeConstraints { + $0.top.equalTo(firstButton.snp.bottom).offset(8) + $0.leading.trailing.equalTo(safeAreaLayoutGuide).inset(width * (20/375)) + $0.height.equalTo(44) + } + } +} diff --git a/HealthFoodMe/HealthFoodMe/Presentation/Common/HelpmeAlerts/Views/ReviewDeleteAlertView.swift b/HealthFoodMe/HealthFoodMe/Presentation/Common/HelpmeAlerts/Views/ReviewDeleteAlertView.swift new file mode 100644 index 00000000..e9579d95 --- /dev/null +++ b/HealthFoodMe/HealthFoodMe/Presentation/Common/HelpmeAlerts/Views/ReviewDeleteAlertView.swift @@ -0,0 +1,113 @@ +// +// ReviewDeleteAlertView.swift +// HealthFoodMe +// +// Created by 김영인 on 2022/07/15. +// + +import UIKit + +import SnapKit + +class ReviewDeleteAlertView: UIView { + + // MARK: - Properties + + let width = UIScreen.main.bounds.width + weak var delegate: AlertDelegate? + + // MARK: - UI Components + + private var titleLabel: UILabel = { + let lb = UILabel() + lb.textColor = .helfmeBlack + lb.font = .NotoMedium(size: 16) + lb.numberOfLines = 0 + lb.textAlignment = .center + return lb + }() + + private lazy var firstButton: UIButton = { + let btn = UIButton() + btn.backgroundColor = .mainRed + btn.setTitleColor(UIColor.helfmeWhite, for: .normal) + btn.setTitle(I18N.HelfmeAlert.yes, for: .normal) + btn.titleLabel?.font = .NotoBold(size: 15) + btn.layer.cornerRadius = 8 + btn.addTarget(self, action: #selector(didTapReviewDelete), for: .touchUpInside) + return btn + }() + + private lazy var secondButton: UIButton = { + let btn = UIButton() + btn.backgroundColor = .helfmeWhite + btn.setTitleColor(UIColor.helfmeGray1, for: .normal) + btn.setTitle(I18N.HelfmeAlert.no, for: .normal) + btn.titleLabel?.textColor = .helfmeGray1 + btn.titleLabel?.font = .NotoBold(size: 15) + btn.layer.cornerRadius = 8 + btn.layer.borderColor = UIColor.helfmeLineGray.cgColor + btn.layer.borderWidth = 1 + btn.addTarget(self, action: #selector(didTapReviewDeleteClose), for: .touchUpInside) + return btn + }() + + // MARK: - View Life Cycle + + override init(frame: CGRect) { + super.init(frame: frame) + setUI() + setLayout() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} + +// MARK: - @objc Methods + +extension ReviewDeleteAlertView { + @objc func didTapReviewDelete() { + delegate?.alertDidTap() + } + + @objc func didTapReviewDeleteClose() { + delegate?.alertDismiss() + } +} + +// MARK: - Methods + +extension ReviewDeleteAlertView { + func setData(title: String?) { + titleLabel.text = title + } + + private func setUI() { + backgroundColor = .helfmeWhite + } + + private func setLayout() { + addSubviews(titleLabel, + firstButton, + secondButton) + + titleLabel.snp.makeConstraints { + $0.top.equalTo(safeAreaLayoutGuide).offset(30) + $0.centerX.equalTo(safeAreaLayoutGuide) + } + + firstButton.snp.makeConstraints { + $0.top.equalTo(titleLabel.snp.bottom).offset(24) + $0.leading.trailing.equalTo(safeAreaLayoutGuide).inset(width * (20/375)) + $0.height.equalTo(44) + } + + secondButton.snp.makeConstraints { + $0.top.equalTo(firstButton.snp.bottom).offset(8) + $0.leading.trailing.equalTo(safeAreaLayoutGuide).inset(width * (20/375)) + $0.height.equalTo(44) + } + } +} diff --git a/HealthFoodMe/HealthFoodMe/Presentation/Common/HelpmeAlerts/Views/WithdrawalAlertView.swift b/HealthFoodMe/HealthFoodMe/Presentation/Common/HelpmeAlerts/Views/WithdrawalAlertView.swift new file mode 100644 index 00000000..6afb3083 --- /dev/null +++ b/HealthFoodMe/HealthFoodMe/Presentation/Common/HelpmeAlerts/Views/WithdrawalAlertView.swift @@ -0,0 +1,136 @@ +// +// WithdrawalAlertView.swift +// HealthFoodMe +// +// Created by 김영인 on 2022/07/15. +// + +import UIKit + +import SnapKit + +class WithdrawalAlertView: UIView { + + // MARK: - Properties + + let width = UIScreen.main.bounds.width + weak var delegate: AlertDelegate? + + // MARK: - UI Components + + private var titleLabel: UILabel = { + let lb = UILabel() + lb.textColor = .helfmeBlack + lb.font = .NotoMedium(size: 16) + return lb + }() + + private var subtitleLabel: UILabel = { + let lb = UILabel() + lb.textColor = .helfmeBlack + lb.font = .NotoRegular(size: 12) + lb.numberOfLines = 0 + lb.textAlignment = .center + return lb + }() + + private lazy var firstButton: UIButton = { + let btn = UIButton() + btn.backgroundColor = .mainRed + btn.setTitleColor(UIColor.helfmeWhite, for: .normal) + btn.setTitle(I18N.HelfmeAlert.no, for: .normal) + btn.titleLabel?.font = .NotoBold(size: 15) + btn.layer.cornerRadius = 8 + btn.addTarget(self, action: #selector(didTapWithdrawalClose), for: .touchUpInside) + return btn + }() + + private lazy var secondButton: UIButton = { + let btn = UIButton() + btn.backgroundColor = .helfmeWhite + btn.setTitleColor(UIColor.helfmeGray2, for: .normal) + btn.setTitle(I18N.HelfmeAlert.withdrawalYes, for: .normal) + btn.titleLabel?.font = .NotoRegular(size: 12) + btn.addTarget(self, action: #selector(didTapWithdrawal), for: .touchUpInside) + return btn + }() + + private var lineView: UIView = { + let view = UIView() + view.backgroundColor = .helfmeGray2 + return view + }() + + // MARK: - View Life Cycle + + override init(frame: CGRect) { + super.init(frame: frame) + setUI() + setLayout() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} + +// MARK: - @objc Methods + +extension WithdrawalAlertView { + @objc func didTapWithdrawal() { + delegate?.alertDidTap() + } + + @objc func didTapWithdrawalClose() { + delegate?.alertDismiss() + } +} + +// MARK: - Methods + +extension WithdrawalAlertView { + func setData(title: String?, subtitle: String?) { + titleLabel.text = title + subtitleLabel.text = subtitle + } + + private func setUI() { + backgroundColor = .helfmeWhite + } + + private func setLayout() { + addSubviews(titleLabel, + subtitleLabel, + firstButton, + secondButton, + lineView) + + titleLabel.snp.makeConstraints { + $0.top.equalTo(safeAreaLayoutGuide).offset(32) + $0.centerX.equalTo(safeAreaLayoutGuide) + } + + subtitleLabel.snp.makeConstraints { + $0.top.equalTo(titleLabel.snp.bottom).offset(8) + $0.leading.trailing.equalTo(safeAreaLayoutGuide).inset(width * (50/375)) + } + + firstButton.snp.makeConstraints { + $0.top.equalTo(subtitleLabel.snp.bottom).offset(24) + $0.leading.trailing.equalTo(safeAreaLayoutGuide).inset(width * (20/375)) + $0.height.equalTo(44) + } + + secondButton.snp.makeConstraints { + $0.top.equalTo(firstButton.snp.bottom).offset(12) + $0.centerX.equalTo(safeAreaLayoutGuide) + $0.height.equalTo(21) + } + + lineView.snp.makeConstraints { + $0.top.equalTo(secondButton.snp.bottom).offset(-3) + $0.leading.trailing.equalTo(secondButton) + $0.height.equalTo(0.5) + } + } +}