格式化日志页面添加完成按钮

This commit is contained in:
2026-07-12 21:01:36 +08:00
parent 230a9ad260
commit b2e36227b6
+19
View File
@@ -11,6 +11,7 @@ class FormatLogViewController: UIViewController {
private var textView: UITextView! private var textView: UITextView!
private var formatButton: UIButton! private var formatButton: UIButton!
private var doneButton: UIBarButtonItem!
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
@@ -27,8 +28,11 @@ class FormatLogViewController: UIViewController {
textView.backgroundColor = .white textView.backgroundColor = .white
textView.layer.cornerRadius = 12 textView.layer.cornerRadius = 12
textView.textContainerInset = UIEdgeInsets(top: 12, left: 12, bottom: 12, right: 12) textView.textContainerInset = UIEdgeInsets(top: 12, left: 12, bottom: 12, right: 12)
textView.delegate = self
view.addSubview(textView) view.addSubview(textView)
doneButton = UIBarButtonItem(title: "完成", style: .prominent, target: self, action: #selector(didTapDoneButton))
formatButton = UIButton(type: .system) formatButton = UIButton(type: .system)
formatButton.translatesAutoresizingMaskIntoConstraints = false formatButton.translatesAutoresizingMaskIntoConstraints = false
formatButton.setTitle("格式化", for: .normal) formatButton.setTitle("格式化", for: .normal)
@@ -50,4 +54,19 @@ class FormatLogViewController: UIViewController {
formatButton.heightAnchor.constraint(equalToConstant: 52) 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
}
} }