整体样式改为 iOS 设置页风格并适配暗色模式
This commit is contained in:
@@ -1,38 +0,0 @@
|
|||||||
//
|
|
||||||
// Color+Hex.swift
|
|
||||||
// Note
|
|
||||||
//
|
|
||||||
// Created by fish on 2026/7/12.
|
|
||||||
//
|
|
||||||
|
|
||||||
import SwiftUI
|
|
||||||
|
|
||||||
extension Color {
|
|
||||||
init(hex: String) {
|
|
||||||
let trimmed = hex.trimmingCharacters(in: CharacterSet.alphanumerics.inverted)
|
|
||||||
var int: UInt64 = 0
|
|
||||||
Scanner(string: trimmed).scanHexInt64(&int)
|
|
||||||
let r, g, b: UInt64
|
|
||||||
switch trimmed.count {
|
|
||||||
case 6:
|
|
||||||
r = (int >> 16) & 0xFF
|
|
||||||
g = (int >> 8) & 0xFF
|
|
||||||
b = int & 0xFF
|
|
||||||
case 8:
|
|
||||||
r = (int >> 16) & 0xFF
|
|
||||||
g = (int >> 8) & 0xFF
|
|
||||||
b = int & 0xFF
|
|
||||||
default:
|
|
||||||
r = 0
|
|
||||||
g = 0
|
|
||||||
b = 0
|
|
||||||
}
|
|
||||||
self.init(
|
|
||||||
.sRGB,
|
|
||||||
red: Double(r) / 255,
|
|
||||||
green: Double(g) / 255,
|
|
||||||
blue: Double(b) / 255,
|
|
||||||
opacity: 1
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+61
-79
@@ -15,74 +15,14 @@ struct FormatterView: View {
|
|||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationStack {
|
NavigationStack {
|
||||||
VStack(spacing: 0) {
|
List {
|
||||||
headerView
|
inputSection
|
||||||
.background(Color(hex: "f2f2f7"))
|
actionSection
|
||||||
|
resultSection
|
||||||
ScrollView {
|
|
||||||
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)
|
|
||||||
)
|
|
||||||
.toolbar {
|
|
||||||
ToolbarItemGroup(placement: .keyboard) {
|
|
||||||
Spacer()
|
|
||||||
Button("完成") {
|
|
||||||
dismissKeyboard()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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"))
|
|
||||||
}
|
|
||||||
.background(Color(hex: "f2f2f7").ignoresSafeArea())
|
|
||||||
.onTapGesture {
|
|
||||||
dismissKeyboard()
|
|
||||||
}
|
}
|
||||||
|
.listStyle(.insetGrouped)
|
||||||
|
.navigationTitle("文案格式化")
|
||||||
|
.background(Color(.systemGroupedBackground).ignoresSafeArea())
|
||||||
.alert("提示", isPresented: $showEmptyAlert) {
|
.alert("提示", isPresented: $showEmptyAlert) {
|
||||||
Button("确定", role: .cancel) {}
|
Button("确定", role: .cancel) {}
|
||||||
} message: {
|
} message: {
|
||||||
@@ -104,24 +44,65 @@ struct FormatterView: View {
|
|||||||
.transition(.opacity)
|
.transition(.opacity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.navigationBarHidden(true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var headerView: some View {
|
private var inputSection: some View {
|
||||||
|
Section {
|
||||||
|
TextEditor(text: $inputText)
|
||||||
|
.frame(minHeight: 160)
|
||||||
|
.scrollContentBackground(.hidden)
|
||||||
|
.background(Color(.secondarySystemGroupedBackground))
|
||||||
|
.toolbar {
|
||||||
|
ToolbarItemGroup(placement: .keyboard) {
|
||||||
|
Spacer()
|
||||||
|
Button("完成") {
|
||||||
|
dismissKeyboard()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} header: {
|
||||||
|
Text("输入")
|
||||||
|
} footer: {
|
||||||
|
Text("粘贴需要格式化的文案")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var actionSection: some View {
|
||||||
|
Section {
|
||||||
|
Button(action: formatText) {
|
||||||
HStack {
|
HStack {
|
||||||
Text("文案格式化")
|
Spacer()
|
||||||
.font(.largeTitle.bold())
|
Label("格式化", systemImage: "wand.and.stars")
|
||||||
.foregroundStyle(.primary)
|
.font(.headline)
|
||||||
Spacer()
|
Spacer()
|
||||||
}
|
}
|
||||||
.frame(maxWidth: .infinity, minHeight: 44)
|
}
|
||||||
.padding(.horizontal)
|
}
|
||||||
.padding(.top, 8)
|
}
|
||||||
.padding(.bottom, 8)
|
|
||||||
.contentShape(Rectangle())
|
private var resultSection: some View {
|
||||||
.onTapGesture {
|
Section {
|
||||||
dismissKeyboard()
|
if outputText.isEmpty {
|
||||||
|
Text("点击上方按钮生成格式化结果")
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
} else {
|
||||||
|
TextEditor(text: .constant(outputText))
|
||||||
|
.frame(minHeight: 160)
|
||||||
|
.scrollContentBackground(.hidden)
|
||||||
|
.background(Color(.secondarySystemGroupedBackground))
|
||||||
|
}
|
||||||
|
} header: {
|
||||||
|
HStack {
|
||||||
|
Text("格式化结果")
|
||||||
|
Spacer()
|
||||||
|
if !outputText.isEmpty {
|
||||||
|
Button(action: copyOutput) {
|
||||||
|
Image(systemName: "doc.on.doc")
|
||||||
|
}
|
||||||
|
.font(.subheadline)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,6 +148,7 @@ struct FormatterView: View {
|
|||||||
content = content.replacingOccurrences(of: "三、工作方面", with: "## 三、工作方面")
|
content = content.replacingOccurrences(of: "三、工作方面", with: "## 三、工作方面")
|
||||||
|
|
||||||
outputText = content
|
outputText = content
|
||||||
|
dismissKeyboard()
|
||||||
}
|
}
|
||||||
|
|
||||||
private func copyOutput() {
|
private func copyOutput() {
|
||||||
|
|||||||
Reference in New Issue
Block a user