diff --git a/Projects/Presentation/Sources/Report/View/Component/ReportRegistration/ReportTextView.swift b/Projects/Presentation/Sources/Report/View/Component/ReportRegistration/ReportTextView.swift index 8640e66..4424209 100644 --- a/Projects/Presentation/Sources/Report/View/Component/ReportRegistration/ReportTextView.swift +++ b/Projects/Presentation/Sources/Report/View/Component/ReportRegistration/ReportTextView.swift @@ -34,9 +34,14 @@ final class ReportTextView: UIView { private let textView = UITextView() private let chevronImage = UIImageView() private let button = UIButton() + private var maxLength: Int? weak var delegate: ReportTextViewDelegate? + override var isFirstResponder: Bool { + return textView.isFirstResponder + } - init(type: ReportTextViewType, placeholder: String?) { + init(type: ReportTextViewType, placeholder: String?, maxLength: Int? = nil) { + self.maxLength = maxLength super.init(frame: .zero) configureAttribute(type: type, placeholder: placeholder) configureLayout(type: type) @@ -158,6 +163,11 @@ extension ReportTextView: UITextViewDelegate { func textViewDidChange(_ textView: UITextView) { updatePlaceholderVisibility() + + if let maxLength = self.maxLength, (textView.text?.count ?? 0) > maxLength { + textView.text = String(textView.text?.prefix(maxLength) ?? "") + } + delegate?.reportTextViewDidChanged(self, text: textView.text) } @@ -165,4 +175,13 @@ extension ReportTextView: UITextViewDelegate { updatePlaceholderVisibility() delegate?.reportTextViewDidChanged(self, text: textView.text) } + + func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool { + guard let maxLength = self.maxLength else { return true } + + let currentString = (textView.text ?? "") as NSString + let newString = currentString.replacingCharacters(in: range, with: text) + + return newString.count <= maxLength + } } diff --git a/Projects/Presentation/Sources/Report/View/ReportRegistrationViewController.swift b/Projects/Presentation/Sources/Report/View/ReportRegistrationViewController.swift index f2b6641..6b2d0d2 100644 --- a/Projects/Presentation/Sources/Report/View/ReportRegistrationViewController.swift +++ b/Projects/Presentation/Sources/Report/View/ReportRegistrationViewController.swift @@ -63,7 +63,10 @@ final class ReportRegistrationViewController: BaseViewController 0 else { + let message = "더 이상 사진을 선택할 수 없습니다." + let alertController = UIAlertController(title: "알림", message: message, preferredStyle: .alert) + alertController.addAction(UIAlertAction(title: "확인", style: .default)) + self.present(alertController, animated: true) + return + } + let picker = PHPickerViewController(configuration: config) picker.delegate = self present(picker, animated: true) @@ -537,6 +552,24 @@ final class ReportRegistrationViewController: BaseViewController