diff --git a/NADA-iOS-forRelease.xcodeproj/project.pbxproj b/NADA-iOS-forRelease.xcodeproj/project.pbxproj index d6b81646..b4ba79cd 100644 --- a/NADA-iOS-forRelease.xcodeproj/project.pbxproj +++ b/NADA-iOS-forRelease.xcodeproj/project.pbxproj @@ -7,9 +7,11 @@ objects = { /* Begin PBXBuildFile section */ + 39007F2C27080D8200E7143E /* UIViewController+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39007F2B27080D8200E7143E /* UIViewController+Extension.swift */; }; 390515B82706CEBB00C5F7A5 /* Colors.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 390515B72706CEBB00C5F7A5 /* Colors.xcassets */; }; 390515BA2706D29B00C5F7A5 /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 390515B92706D29B00C5F7A5 /* Color.swift */; }; 3909242F26FA15E800236C51 /* UIView+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3909242E26FA15E800236C51 /* UIView+Extension.swift */; }; + 39488E352706E17200BDC917 /* UIAlertController+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39488E342706E17200BDC917 /* UIAlertController+Extension.swift */; }; 39523E09270184A700536900 /* CardListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39523E08270184A700536900 /* CardListViewController.swift */; }; 39523E0B270184B100536900 /* CardList.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 39523E0A270184B100536900 /* CardList.storyboard */; }; 39523E5B2701A48900536900 /* CardListTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39523E592701A48900536900 /* CardListTableViewCell.swift */; }; @@ -51,9 +53,11 @@ /* Begin PBXFileReference section */ 1E770167DDA25A2CE063AA5C /* Pods-NADA-iOS-forRelease.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NADA-iOS-forRelease.release.xcconfig"; path = "Target Support Files/Pods-NADA-iOS-forRelease/Pods-NADA-iOS-forRelease.release.xcconfig"; sourceTree = ""; }; + 39007F2B27080D8200E7143E /* UIViewController+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+Extension.swift"; sourceTree = ""; }; 390515B72706CEBB00C5F7A5 /* Colors.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Colors.xcassets; sourceTree = ""; }; 390515B92706D29B00C5F7A5 /* Color.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = ""; }; 3909242E26FA15E800236C51 /* UIView+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Extension.swift"; sourceTree = ""; }; + 39488E342706E17200BDC917 /* UIAlertController+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIAlertController+Extension.swift"; sourceTree = ""; }; 39523E08270184A700536900 /* CardListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardListViewController.swift; sourceTree = ""; }; 39523E0A270184B100536900 /* CardList.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = CardList.storyboard; sourceTree = ""; }; 39523E592701A48900536900 /* CardListTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardListTableViewCell.swift; sourceTree = ""; }; @@ -370,6 +374,8 @@ children = ( F8FC43A626C020780033E151 /* TempExtensions.swift */, 3909242E26FA15E800236C51 /* UIView+Extension.swift */, + 39488E342706E17200BDC917 /* UIAlertController+Extension.swift */, + 39007F2B27080D8200E7143E /* UIViewController+Extension.swift */, ); path = Extensions; sourceTree = ""; @@ -529,10 +535,12 @@ F8FC43B126C020A70033E151 /* TempNetwork.swift in Sources */, F858079E2700354E00872484 /* CardBackgroundSettingCell.swift in Sources */, F8FC438A26C01CDD0033E151 /* MainViewController.swift in Sources */, + 39007F2C27080D8200E7143E /* UIViewController+Extension.swift in Sources */, 3909242F26FA15E800236C51 /* UIView+Extension.swift in Sources */, 39523E09270184A700536900 /* CardListViewController.swift in Sources */, F83206AA26F61E3700D61711 /* FrontCardCell.swift in Sources */, 3979709626FA0BE5003FB4F5 /* LoginViewController.swift in Sources */, + 39488E352706E17200BDC917 /* UIAlertController+Extension.swift in Sources */, F8FC43AF26C0209A0033E151 /* TempModel.swift in Sources */, F8FC43A726C020780033E151 /* TempExtensions.swift in Sources */, F8FC43B826C0227D0033E151 /* Const.swift in Sources */, diff --git a/NADA-iOS-forRelease/Resouces/Extensions/UIAlertController+Extension.swift b/NADA-iOS-forRelease/Resouces/Extensions/UIAlertController+Extension.swift new file mode 100644 index 00000000..e57db7d7 --- /dev/null +++ b/NADA-iOS-forRelease/Resouces/Extensions/UIAlertController+Extension.swift @@ -0,0 +1,50 @@ +// +// UIAlertController+Extension.swift +// NADA-iOS-forRelease +// +// Created by 민 on 2021/10/01. +// + +import Foundation +import UIKit + +extension UIAlertController { + // Set title font and title color + func setTitle(font: UIFont?, color: UIColor?) { + guard let title = self.title else { return } + let attributeString = NSMutableAttributedString(string: title) + + if let titleFont = font { + attributeString.addAttributes([NSAttributedString.Key.font: titleFont], + range: NSRange(location: 0, length: title.count)) + } + if let titleColor = color { + attributeString.addAttributes([NSAttributedString.Key.foregroundColor: titleColor], + range: NSRange(location: 0, length: title.count)) + } + self.setValue(attributeString, forKey: "attributedTitle") + + } + + // Set message font and message color + func setMessage(font: UIFont?, color: UIColor?) { + guard let message = self.message else { return } + let attributeString = NSMutableAttributedString(string: message) + if let messageFont = font { + attributeString.addAttributes([NSAttributedString.Key.font: messageFont], + range: NSRange(location: 0, length: message.count)) + } + + if let messageColorColor = color { + attributeString.addAttributes([NSAttributedString.Key.foregroundColor: messageColorColor], + range: NSRange(location: 0, length: message.count)) + + } + self.setValue(attributeString, forKey: "attributedMessage") + } + + // Set tint color of UIAlertController + func setTint(color: UIColor) { + self.view.tintColor = color + } +} diff --git a/NADA-iOS-forRelease/Resouces/Extensions/UIViewController+Extension.swift b/NADA-iOS-forRelease/Resouces/Extensions/UIViewController+Extension.swift new file mode 100644 index 00000000..2dff1555 --- /dev/null +++ b/NADA-iOS-forRelease/Resouces/Extensions/UIViewController+Extension.swift @@ -0,0 +1,35 @@ +// +// UIViewController+Extension.swift +// NADA-iOS-forRelease +// +// Created by 민 on 2021/10/02. +// + +import Foundation +import UIKit + +extension UIViewController { + // Common Alert + func makeAlert(title: String, + message: String, + cancelAction: ((UIAlertAction) -> Void)? = nil, + deleteAction: ((UIAlertAction) -> Void)?, + completion: (() -> Void)? = nil) { + + let alertViewController = UIAlertController(title: title, message: message, preferredStyle: .alert) + + alertViewController.setTitle(font: UIFont.boldSystemFont(ofSize: 17), color: UIColor.white) + alertViewController.setMessage(font: UIFont.systemFont(ofSize: 13), color: UIColor.white) + alertViewController.setTint(color: Colors.mainBlue.color) + + alertViewController.view.subviews.first?.subviews.first?.subviews.first?.backgroundColor = UIColor(red: 30/255, green: 30/255, blue: 30/255, alpha: 3/4) + + let cancelAction = UIAlertAction(title: "취소", style: .cancel, handler: cancelAction) + alertViewController.addAction(cancelAction) + + let deleteAction = UIAlertAction(title: "삭제", style: .default, handler: deleteAction) + alertViewController.addAction(deleteAction) + + self.present(alertViewController, animated: true, completion: completion) + } +} diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/CardList/CardListViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/CardList/CardListViewController.swift index 82d7a9d1..46dcb3f2 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/CardList/CardListViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/CardList/CardListViewController.swift @@ -50,7 +50,12 @@ extension CardListViewController: UITableViewDelegate { // Swipe Action func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { - let deleteAction = UIContextualAction(style: .normal, title: "삭제", handler: { (action, view, success) in + let deleteAction = UIContextualAction(style: .normal, title: "삭제", handler: { (_ action, _ view, _ success) in + self.makeAlert(title: "명함 삭제", message: "명함을 정말 삭제하시겠습니까?", cancelAction: { _ in + // 취소 눌렀을 때 액션이 들어갈 부분 + }, deleteAction: { _ in + // 삭제 눌렀을 때 액션이 들어갈 부분 + }, completion: nil) }) deleteAction.backgroundColor = .red