// // FormatLogViewController.swift // Note // // Created by fish on 2026/7/12. // import UIKit class FormatLogViewController: UIViewController { private var textView: UITextView! private var formatButton: UIButton! private var doneButton: UIBarButtonItem! override func viewDidLoad() { super.viewDidLoad() title = "格式化日志" navigationItem.largeTitleDisplayMode = .never view.backgroundColor = .systemGroupedBackground setupUI() } private func setupUI() { textView = UITextView() textView.translatesAutoresizingMaskIntoConstraints = false textView.font = UIFont.systemFont(ofSize: 16) 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) formatButton.titleLabel?.font = UIFont.systemFont(ofSize: 18, weight: .semibold) formatButton.backgroundColor = .systemBlue formatButton.setTitleColor(.white, for: .normal) formatButton.layer.cornerRadius = 12 view.addSubview(formatButton) NSLayoutConstraint.activate([ textView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 16), textView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16), textView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -16), textView.bottomAnchor.constraint(equalTo: formatButton.topAnchor, constant: -16), formatButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16), formatButton.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -16), formatButton.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -16), 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 } }