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("完成") {