Skip to content

Commit

Permalink
[FEAT] #117 - 명함생성 뷰 글자제한 구현
Browse files Browse the repository at this point in the history
### Descriptions
- 명함생성 뷰 글자제한 구현.
- maxLength 보다 긴 문자열 붙여넣기해도 maxLength 만큼만 입력됨.
  • Loading branch information
hyun99999 committed Dec 8, 2021
1 parent 52159f9 commit 3a8b674
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 4 deletions.
4 changes: 2 additions & 2 deletions NADA-iOS-forRelease.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand All @@ -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)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -42,6 +45,7 @@ class BackCardCreationCollectionViewCell: UICollectionViewCell {
setUI()
registerCell()
textFieldDelegate()
setNotification()
}
}

Expand Down Expand Up @@ -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..<maxIndex])
firstTMITextField.text = newString
}
}
case secondTMITextField:
if let text = secondTMITextField.text {
if text.count > maxLength {
let maxIndex = text.index(text.startIndex, offsetBy: maxLength)
let newString = String(text[text.startIndex..<maxIndex])
secondTMITextField.text = newString
}
}
case thirdTMITextField:
if let text = thirdTMITextField.text {
if text.count > maxLength {
let maxIndex = text.index(text.startIndex, offsetBy: maxLength)
let newString = String(text[text.startIndex..<maxIndex])
thirdTMITextField.text = newString
}
}
default:
return
}
}
}
}

// MARK: - UICollectionViewDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class FrontCardCreationCollectionViewCell: UICollectionViewCell {
private var optionalTextFieldList = [UITextField]()
private var cardBackgroundImage: UIImage?
private var defaultImageIndex: Int?
private let maxLength: Int = 15

public var presentingBirthBottomVCClosure: (() -> Void)?
public var presentingMBTIBottomVCClosure: (() -> Void)?
Expand Down Expand Up @@ -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 가 편집되었는지. 필수 항목이 다 입력되었는지 체크.
Expand Down Expand Up @@ -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..<maxIndex])
cardTitleTextField.text = newString
}
}
case userNameTextField:
if let text = userNameTextField.text {
if text.count > maxLength {
let maxIndex = text.index(text.startIndex, offsetBy: maxLength)
let newString = String(text[text.startIndex..<maxIndex])
userNameTextField.text = newString
}
}
case descriptionTextField:
if let text = descriptionTextField.text {
if text.count > maxLength {
let maxIndex = text.index(text.startIndex, offsetBy: maxLength)
let newString = String(text[text.startIndex..<maxIndex])
descriptionTextField.text = newString
}
}
default:
return
}
}
}
}

// MARK: - UICollectionViewDelegate
extension FrontCardCreationCollectionViewCell: UICollectionViewDelegate {

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

switch indexPath.item {
case 0:
NotificationCenter.default.post(name: .presentingImagePicker, object: nil)
Expand Down

0 comments on commit 3a8b674

Please sign in to comment.