Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#20] - 명함 리스트뷰 Alert창 구현 & 연결 #21

Merged
merged 2 commits into from
Oct 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions NADA-iOS-forRelease.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 = "<group>"; };
39007F2B27080D8200E7143E /* UIViewController+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+Extension.swift"; sourceTree = "<group>"; };
390515B72706CEBB00C5F7A5 /* Colors.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Colors.xcassets; sourceTree = "<group>"; };
390515B92706D29B00C5F7A5 /* Color.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = "<group>"; };
3909242E26FA15E800236C51 /* UIView+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Extension.swift"; sourceTree = "<group>"; };
39488E342706E17200BDC917 /* UIAlertController+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIAlertController+Extension.swift"; sourceTree = "<group>"; };
39523E08270184A700536900 /* CardListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardListViewController.swift; sourceTree = "<group>"; };
39523E0A270184B100536900 /* CardList.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = CardList.storyboard; sourceTree = "<group>"; };
39523E592701A48900536900 /* CardListTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardListTableViewCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -370,6 +374,8 @@
children = (
F8FC43A626C020780033E151 /* TempExtensions.swift */,
3909242E26FA15E800236C51 /* UIView+Extension.swift */,
39488E342706E17200BDC917 /* UIAlertController+Extension.swift */,
39007F2B27080D8200E7143E /* UIViewController+Extension.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down