001project_wildgrowth/ios/WildGrowth/WildGrowth/GlobalStyles.swift

52 lines
1.6 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import SwiftUI
//
struct RoundedCorner: Shape {
var radius: CGFloat = .infinity
var corners: UIRectCorner = .allCorners
func path(in rect: CGRect) -> Path {
let path = UIBezierPath(
roundedRect: rect,
byRoundingCorners: corners,
cornerRadii: CGSize(width: radius, height: radius)
)
return Path(path.cgPath)
}
}
//
extension View {
func cornerRadius(_ radius: CGFloat, corners: UIRectCorner) -> some View {
clipShape(RoundedCorner(radius: radius, corners: corners))
}
}
//
struct ISO8601DateFormatters {
static let full: ISO8601DateFormatter = {
let formatter = ISO8601DateFormatter()
if #available(iOS 11.0, *) {
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
} else {
formatter.formatOptions = [.withInternetDateTime]
}
return formatter
}()
static let simple: ISO8601DateFormatter = {
let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime]
return formatter
}()
//
static func date(from string: String) -> Date? {
if let date = full.date(from: string) { return date }
if let date = simple.date(from: string) { return date }
print("⚠️ [DateFormatter] 解析失败: \(string)")
print(" 尝试的格式: [.withInternetDateTime, .withFractionalSeconds] 和 [.withInternetDateTime]")
return nil
}
}