From 3a8b674c146f41f43ce5b459b4d8def9c54606d3 Mon Sep 17 00:00:00 2001 From: hyungyu Kim Date: Wed, 8 Dec 2021 11:04:33 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT]=20#117=20-=20=EB=AA=85=ED=95=A8=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EB=B7=B0=20=EA=B8=80=EC=9E=90=EC=A0=9C=ED=95=9C=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Descriptions - 명함생성 뷰 글자제한 구현. - maxLength 보다 긴 문자열 붙여넣기해도 maxLength 만큼만 입력됨. --- NADA-iOS-forRelease.xcodeproj/project.pbxproj | 4 +- .../BackCardCreationCollectionViewCell.swift | 43 +++++++++++++++++++ .../FrontCardCreationCollectionViewCell.swift | 37 +++++++++++++++- 3 files changed, 80 insertions(+), 4 deletions(-) diff --git a/NADA-iOS-forRelease.xcodeproj/project.pbxproj b/NADA-iOS-forRelease.xcodeproj/project.pbxproj index e18a67ff..bec52429 100644 --- a/NADA-iOS-forRelease.xcodeproj/project.pbxproj +++ b/NADA-iOS-forRelease.xcodeproj/project.pbxproj @@ -1182,7 +1182,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = 4QG3GC35LA; + DEVELOPMENT_TEAM = T3VFJ764ZC; INFOPLIST_FILE = "NADA-iOS-forRelease/Info.plist"; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -1202,7 +1202,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = 4QG3GC35LA; + DEVELOPMENT_TEAM = T3VFJ764ZC; INFOPLIST_FILE = "NADA-iOS-forRelease/Info.plist"; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", diff --git a/NADA-iOS-forRelease/Sources/Cells/CreationCard/BackCardCreationCollectionViewCell.swift b/NADA-iOS-forRelease/Sources/Cells/CreationCard/BackCardCreationCollectionViewCell.swift index f9fb3b2f..3d16a5e7 100644 --- a/NADA-iOS-forRelease/Sources/Cells/CreationCard/BackCardCreationCollectionViewCell.swift +++ b/NADA-iOS-forRelease/Sources/Cells/CreationCard/BackCardCreationCollectionViewCell.swift @@ -12,9 +12,12 @@ class BackCardCreationCollectionViewCell: UICollectionViewCell { // MARK: - Properties static let identifier = "BackCardCreationCollectionViewCell" + private let flavorList = ["민초", "반민초", "소주", "맥주", "부먹", "찍먹", "양념", "후라이드"] + private let maxLength: Int = 20 private var textFieldList = [UITextField]() private var requiredCollectionViewList = [UICollectionView]() + public weak var backCardCreationDelegate: BackCardCreationDelegate? // MARK: - @IBOutlet Properties @@ -42,6 +45,7 @@ class BackCardCreationCollectionViewCell: UICollectionViewCell { setUI() registerCell() textFieldDelegate() + setNotification() } } @@ -109,9 +113,48 @@ extension BackCardCreationCollectionViewCell { private func textFieldDelegate() { _ = textFieldList.map { $0.delegate = self } } + private func setNotification() { + NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidChange(_:)), name: UITextField.textDidChangeNotification, object: nil) + } static func nib() -> UINib { return UINib(nibName: Const.Xib.backCardCreationCollectionViewCell, bundle: Bundle(for: BackCardCreationCollectionViewCell.self)) } + + // MARK: - @objc Methods + + @objc + private func textFieldDidChange(_ notification: NSNotification) { + if let textField = notification.object as? UITextField { + switch textField { + case firstTMITextField: + if let text = firstTMITextField.text { + if text.count > maxLength { + let maxIndex = text.index(text.startIndex, offsetBy: maxLength) + let newString = String(text[text.startIndex.. maxLength { + let maxIndex = text.index(text.startIndex, offsetBy: maxLength) + let newString = String(text[text.startIndex.. maxLength { + let maxIndex = text.index(text.startIndex, offsetBy: maxLength) + let newString = String(text[text.startIndex.. Void)? public var presentingMBTIBottomVCClosure: (() -> Void)? @@ -160,6 +161,7 @@ extension FrontCardCreationCollectionViewCell { NotificationCenter.default.addObserver(self, selector: #selector(setBirthTextField(notification:)), name: .frontCardBirth, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(setMBTITextField(notification:)), name: .frontCardMBTI, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(setCardBackgroundImage(notifiation:)), name: .sendNewImage, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(textFieldDidChange(_:)), name: UITextField.textDidChangeNotification, object: nil) } /// front card 가 편집되었는지. 필수 항목이 다 입력되었는지 체크. @@ -209,13 +211,44 @@ extension FrontCardCreationCollectionViewCell { cardBackgroundImage = notifiation.object as? UIImage backgroundSettingCollectionView.reloadData() } + @objc + private func textFieldDidChange(_ notification: Notification) { + if let textField = notification.object as? UITextField { + switch textField { + case cardTitleTextField: + if let text = cardTitleTextField.text { + if text.count > maxLength { + let maxIndex = text.index(text.startIndex, offsetBy: maxLength) + let newString = String(text[text.startIndex.. maxLength { + let maxIndex = text.index(text.startIndex, offsetBy: maxLength) + let newString = String(text[text.startIndex.. maxLength { + let maxIndex = text.index(text.startIndex, offsetBy: maxLength) + let newString = String(text[text.startIndex..