From aa7a290c730edf6a48c24d6bc6e359eae3cd3383 Mon Sep 17 00:00:00 2001 From: jonnwon Date: Tue, 9 Apr 2024 02:14:44 +0900 Subject: [PATCH] feat : Add clearButton in nameTextView --- .../BoxList/AddBookmark/AddBookmarkView.swift | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/iBox/Sources/BoxList/AddBookmark/AddBookmarkView.swift b/iBox/Sources/BoxList/AddBookmark/AddBookmarkView.swift index 6b4a942..1e4e07b 100644 --- a/iBox/Sources/BoxList/AddBookmark/AddBookmarkView.swift +++ b/iBox/Sources/BoxList/AddBookmark/AddBookmarkView.swift @@ -45,6 +45,12 @@ class AddBookmarkView: UIView { $0.autocorrectionType = .no } + private let clearButton = UIButton().then { + $0.setImage(UIImage(systemName: "xmark.circle.fill"), for: .normal) + $0.tintColor = .systemGray3 + $0.isHidden = true + } + private let separatorView = UIView().then { $0.backgroundColor = .systemGray3 } @@ -111,6 +117,7 @@ class AddBookmarkView: UIView { private func setupProperty() { backgroundColor = .systemGroupedBackground updateTextFieldWithIncomingData() + clearButton.addTarget(self, action: #selector(clearTextView), for: .touchUpInside) button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside) nameTextView.delegate = self urlTextView.delegate = self @@ -119,6 +126,7 @@ class AddBookmarkView: UIView { private func setupHierarchy() { addSubview(textFieldView) addSubview(nameTextView) + addSubview(clearButton) addSubview(separatorView) addSubview(urlTextView) addSubview(nameTextViewPlaceHolder) @@ -150,6 +158,11 @@ class AddBookmarkView: UIView { make.leading.equalTo(nameTextView.snp.leading).offset(5) } + clearButton.snp.makeConstraints { make in + make.top.equalTo(nameTextView.snp.top).offset(7) + make.trailing.equalTo(nameTextView.snp.trailing).offset(-5) + } + separatorView.snp.makeConstraints { make in make.top.equalTo(nameTextView.snp.bottom).offset(10) make.leading.equalTo(nameTextView.snp.leading).offset(5) @@ -202,9 +215,15 @@ class AddBookmarkView: UIView { if let data = data, !data.isEmpty { textField.text = data placeholder.isHidden = true + if textField == nameTextView { + clearButton.isHidden = false + } } else { textField.text = "" placeholder.isHidden = false + if textField == nameTextView { + clearButton.isHidden = true + } } } @@ -221,6 +240,11 @@ class AddBookmarkView: UIView { onTextChange?(isBothTextViewsFilled) } + @objc func clearTextView() { + nameTextView.text = "" + textViewDidChange(nameTextView) + } + @objc private func buttonTapped() { onButtonTapped?() } @@ -255,6 +279,7 @@ extension AddBookmarkView: UITextViewDelegate { if textView == nameTextView { nameTextViewPlaceHolder.isHidden = !nameTextView.text.isEmpty + clearButton.isHidden = nameTextView.text.isEmpty } if textView == urlTextView {