Files
e-party-iOS/yana/Utils/FontManager.swift
edwinQQQ f9f3dec53f feat: 更新Podfile和Podfile.lock,移除Alamofire依赖并添加API认证机制文档
- 注释掉Podfile中的Alamofire依赖,更新Podfile.lock以反映更改。
- 在yana/APIs/API-README.md中新增自动认证Header机制的详细文档,描述其工作原理、实现细节及最佳实践。
- 在yana/yanaApp.swift中将print语句替换为debugInfo以增强调试信息的输出。
- 在API相关文件中实现用户认证状态检查和相关header的自动添加逻辑,提升API请求的安全性和用户体验。
- 更新多个文件中的日志输出,确保在DEBUG模式下提供详细的调试信息。
2025-07-11 16:53:46 +08:00

111 lines
3.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 FontManager {
// MARK: -
enum CustomFont: String, CaseIterable {
case bayonRegular = "Bayon-Regular"
///
var displayName: String {
switch self {
case .bayonRegular:
return "Bayon Regular"
}
}
///
var fileName: String {
return self.rawValue
}
}
// MARK: -
///
/// - Parameters:
/// - customFont:
/// - size:
/// - Returns: Font
static func font(_ customFont: CustomFont, size: CGFloat) -> Font {
return Font.custom(customFont.rawValue, size: size)
}
///
/// - Parameters:
/// - customFont:
/// - designSize: 稿
/// - screenWidth:
/// - Returns: Font
static func adaptedFont(_ customFont: CustomFont, designSize: CGFloat, for screenWidth: CGFloat) -> Font {
let adaptedSize = ScreenAdapter.fontSize(designSize, for: screenWidth)
return Font.custom(customFont.rawValue, size: adaptedSize)
}
///
/// - Parameter customFont:
/// - Returns:
static func isFontAvailable(_ customFont: CustomFont) -> Bool {
let fontNames = UIFont.familyNames
.flatMap { UIFont.fontNames(forFamilyName: $0) }
return fontNames.contains(customFont.rawValue)
}
///
/// - Returns:
static func getAllAvailableFonts() -> [String] {
return UIFont.familyNames
.flatMap { family in
UIFont.fontNames(forFamilyName: family)
.map { _ in "\(family): \(String(describing: font))" }
}
.sorted()
}
///
static func printAllAvailableFonts() {
debugInfo("=== 所有可用字体 ===")
for font in getAllAvailableFonts() {
debugInfo(font)
}
debugInfo("==================")
}
}
// MARK: - SwiftUI View Extension
extension View {
///
/// - Parameters:
/// - customFont:
/// - size:
/// - Returns:
func customFont(_ customFont: FontManager.CustomFont, size: CGFloat) -> some View {
self.font(FontManager.font(customFont, size: size))
}
///
/// - Parameters:
/// - customFont:
/// - designSize: 稿
/// - Returns:
func adaptedCustomFont(_ customFont: FontManager.CustomFont, designSize: CGFloat) -> some View {
self.modifier(AdaptedCustomFontModifier(customFont: customFont, designSize: designSize))
}
}
// MARK: - ViewModifier
struct AdaptedCustomFontModifier: ViewModifier {
let customFont: FontManager.CustomFont
let designSize: CGFloat
func body(content: Content) -> some View {
GeometryReader { geometry in
content
.font(FontManager.adaptedFont(customFont, designSize: designSize, for: geometry.size.width))
}
}
}