From b2e36227b68e0e3da262830c03f80d551befdf2f Mon Sep 17 00:00:00 2001 From: fish Date: Sun, 12 Jul 2026 21:01:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=B7=BB=E5=8A=A0=E5=AE=8C=E6=88=90=E6=8C=89?= =?UTF-8?q?=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Note/FormatLogViewController.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Note/FormatLogViewController.swift b/Note/FormatLogViewController.swift index b96a240..deea6b1 100644 --- a/Note/FormatLogViewController.swift +++ b/Note/FormatLogViewController.swift @@ -11,6 +11,7 @@ class FormatLogViewController: UIViewController { private var textView: UITextView! private var formatButton: UIButton! + private var doneButton: UIBarButtonItem! override func viewDidLoad() { super.viewDidLoad() @@ -27,8 +28,11 @@ class FormatLogViewController: UIViewController { textView.backgroundColor = .white textView.layer.cornerRadius = 12 textView.textContainerInset = UIEdgeInsets(top: 12, left: 12, bottom: 12, right: 12) + textView.delegate = self view.addSubview(textView) + doneButton = UIBarButtonItem(title: "完成", style: .prominent, target: self, action: #selector(didTapDoneButton)) + formatButton = UIButton(type: .system) formatButton.translatesAutoresizingMaskIntoConstraints = false formatButton.setTitle("格式化", for: .normal) @@ -50,4 +54,19 @@ class FormatLogViewController: UIViewController { formatButton.heightAnchor.constraint(equalToConstant: 52) ]) } + + @objc private func didTapDoneButton() { + textView.resignFirstResponder() + } +} + +extension FormatLogViewController: UITextViewDelegate { + + func textViewDidBeginEditing(_ textView: UITextView) { + navigationItem.rightBarButtonItem = doneButton + } + + func textViewDidEndEditing(_ textView: UITextView) { + navigationItem.rightBarButtonItem = nil + } }