Files
e-party-iOS/yana/Utils/FontManager.swift
edwinQQQ 128bf36c88 feat: 更新依赖和项目配置,优化代码结构
- 在Package.swift中注释掉旧的swift-composable-architecture依赖,并添加swift-case-paths依赖。
- 在Podfile中将iOS平台版本更新至16.0,并移除QCloudCOSXML/Transfer依赖,改为使用QCloudCOSXML。
- 更新Podfile.lock以反映依赖变更,确保项目依赖的准确性。
- 新增架构分析需求文档,明确项目架构评估和改进建议。
- 在多个文件中实现async/await语法,提升异步操作的可读性和性能。
- 更新日志输出方法,确保在调试模式下提供一致的调试信息。
- 优化多个视图组件,提升用户体验和代码可维护性。
2025-07-17 18:47:09 +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() {
debugInfoSync("=== 所有可用字体 ===")
for font in getAllAvailableFonts() {
debugInfoSync(font)
}
debugInfoSync("==================")
}
}
// 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))
}
}
}