
- 在Package.swift中注释掉旧的swift-composable-architecture依赖,并添加swift-case-paths依赖。 - 在Podfile中将iOS平台版本更新至16.0,并移除QCloudCOSXML/Transfer依赖,改为使用QCloudCOSXML。 - 更新Podfile.lock以反映依赖变更,确保项目依赖的准确性。 - 新增架构分析需求文档,明确项目架构评估和改进建议。 - 在多个文件中实现async/await语法,提升异步操作的可读性和性能。 - 更新日志输出方法,确保在调试模式下提供一致的调试信息。 - 优化多个视图组件,提升用户体验和代码可维护性。
111 lines
3.6 KiB
Swift
111 lines
3.6 KiB
Swift
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))
|
||
}
|
||
}
|
||
}
|