From aa45062bd745c2884ea8eea3d51f75a0e58b79b0 Mon Sep 17 00:00:00 2001 From: fish Date: Sun, 12 Jul 2026 16:07:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=94=AE=E7=9B=98=E6=94=B6?= =?UTF-8?q?=E8=B5=B7=EF=BC=9A=E6=94=AF=E6=8C=81=E7=82=B9=E5=87=BB=E6=A0=87?= =?UTF-8?q?=E9=A2=98=E6=A0=8F=E5=92=8C=E7=A9=BA=E7=99=BD=E5=8C=BA=E5=9F=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Note/FormatterView.swift | 115 ++++++++++++++++++++++++++------------- 1 file changed, 76 insertions(+), 39 deletions(-) diff --git a/Note/FormatterView.swift b/Note/FormatterView.swift index 569a8ff..917f2c8 100644 --- a/Note/FormatterView.swift +++ b/Note/FormatterView.swift @@ -15,40 +15,13 @@ struct FormatterView: View { var body: some View { NavigationStack { - VStack(spacing: 16) { - TextEditor(text: $inputText) - .frame(minHeight: 160) - .padding(8) - .background(Color(.systemBackground)) - .cornerRadius(8) - .overlay( - RoundedRectangle(cornerRadius: 8) - .stroke(Color(.systemGray4), lineWidth: 1) - ) + VStack(spacing: 0) { + headerView + .background(Color(hex: "f2f2f7")) - Button(action: formatText) { - Label("格式化", systemImage: "wand.and.stars") - .font(.headline) - .frame(maxWidth: .infinity) - .padding() - .background(Color.accentColor) - .foregroundStyle(.white) - .cornerRadius(10) - } - - if !outputText.isEmpty { - VStack(alignment: .leading, spacing: 8) { - HStack { - Text("格式化结果") - .font(.subheadline) - .foregroundStyle(.secondary) - Spacer() - Button(action: copyOutput) { - Image(systemName: "doc.on.doc") - } - } - - TextEditor(text: .constant(outputText)) + ScrollView { + VStack(spacing: 16) { + TextEditor(text: $inputText) .frame(minHeight: 160) .padding(8) .background(Color(.systemBackground)) @@ -57,16 +30,58 @@ struct FormatterView: View { RoundedRectangle(cornerRadius: 8) .stroke(Color(.systemGray4), lineWidth: 1) ) - } - } + .toolbar { + ToolbarItemGroup(placement: .keyboard) { + Spacer() + Button("完成") { + dismissKeyboard() + } + } + } - Spacer() + Button(action: formatText) { + Label("格式化", systemImage: "wand.and.stars") + .font(.headline) + .frame(maxWidth: .infinity) + .padding() + .background(Color.accentColor) + .foregroundStyle(.white) + .cornerRadius(10) + } + + if !outputText.isEmpty { + VStack(alignment: .leading, spacing: 8) { + HStack { + Text("格式化结果") + .font(.subheadline) + .foregroundStyle(.secondary) + Spacer() + Button(action: copyOutput) { + Image(systemName: "doc.on.doc") + } + } + + TextEditor(text: .constant(outputText)) + .frame(minHeight: 160) + .padding(8) + .background(Color(.systemBackground)) + .cornerRadius(8) + .overlay( + RoundedRectangle(cornerRadius: 8) + .stroke(Color(.systemGray4), lineWidth: 1) + ) + } + } + + Spacer(minLength: 16) + } + .padding() + } + .background(Color(hex: "f2f2f7")) } - .padding() - .navigationTitle("文案格式化") .background(Color(hex: "f2f2f7").ignoresSafeArea()) .onTapGesture { - UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) + dismissKeyboard() } .alert("提示", isPresented: $showEmptyAlert) { Button("确定", role: .cancel) {} @@ -89,9 +104,31 @@ struct FormatterView: View { .transition(.opacity) } } + .navigationBarHidden(true) } } + private var headerView: some View { + HStack { + Text("文案格式化") + .font(.largeTitle.bold()) + .foregroundStyle(.primary) + Spacer() + } + .frame(maxWidth: .infinity, minHeight: 44) + .padding(.horizontal) + .padding(.top, 8) + .padding(.bottom, 8) + .contentShape(Rectangle()) + .onTapGesture { + dismissKeyboard() + } + } + + private func dismissKeyboard() { + UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) + } + private func formatText() { if inputText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { showEmptyAlert = true