From bbff0c238d844b9a9b16b96afd75804cacbc4a64 Mon Sep 17 00:00:00 2001 From: fish Date: Sun, 12 Jul 2026 16:01:08 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E9=A1=B5=E9=9D=A2=E8=83=8C?= =?UTF-8?q?=E6=99=AF=E8=89=B2=E4=B8=BA=20f2f2f7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Note/Color+Hex.swift | 38 ++++++++++++++++++++++++++++++++++++++ Note/FormatterView.swift | 1 + Note/ResultView.swift | 1 + 3 files changed, 40 insertions(+) create mode 100644 Note/Color+Hex.swift diff --git a/Note/Color+Hex.swift b/Note/Color+Hex.swift new file mode 100644 index 0000000..348d729 --- /dev/null +++ b/Note/Color+Hex.swift @@ -0,0 +1,38 @@ +// +// 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 + ) + } +} diff --git a/Note/FormatterView.swift b/Note/FormatterView.swift index 767889e..4d0c8f2 100644 --- a/Note/FormatterView.swift +++ b/Note/FormatterView.swift @@ -39,6 +39,7 @@ struct FormatterView: View { } .padding() .navigationTitle("文案格式化") + .background(Color(hex: "f2f2f7").ignoresSafeArea()) .navigationDestination(item: $resultText) { text in ResultView(formattedText: text) } diff --git a/Note/ResultView.swift b/Note/ResultView.swift index 064b868..4c2c271 100644 --- a/Note/ResultView.swift +++ b/Note/ResultView.swift @@ -37,6 +37,7 @@ struct ResultView: View { } .navigationTitle("格式化结果") .navigationBarTitleDisplayMode(.inline) + .background(Color(hex: "f2f2f7").ignoresSafeArea()) .toolbar { ToolbarItem(placement: .topBarTrailing) { Button("完成") {