
- 修改Package.swift以支持iOS 15和macOS 12。 - 更新swift-tca-architecture-guidelines.mdc中的alwaysApply设置为false。 - 注释掉AppDelegate中的NIMSDK导入,移除不再使用的NIMConfigurationManager和NIMSessionManager文件。 - 添加新的API相关文件,包括EMailLoginFeature、IDLoginFeature和相关视图,增强登录功能。 - 更新APIConstants和APIEndpoints以反映新的API路径。 - 添加本地化支持文件,包含英文和中文简体的本地化字符串。 - 新增字体管理和安全工具类,支持AES和DES加密。 - 更新Xcode项目配置,调整版本号和启动画面设置。
114 lines
3.9 KiB
Swift
114 lines
3.9 KiB
Swift
import SwiftUI
|
||
|
||
/// 屏幕适配工具类
|
||
/// 基于设计稿尺寸进行等比例缩放,确保在不同设备上保持一致的视觉效果
|
||
struct ScreenAdapter {
|
||
|
||
// MARK: - 设计稿基准尺寸
|
||
/// 设计稿宽度基准 (iPhone 14 Pro)
|
||
static let designWidth: CGFloat = 393
|
||
/// 设计稿高度基准 (iPhone 14 Pro)
|
||
static let designHeight: CGFloat = 852
|
||
|
||
// MARK: - 适配方法
|
||
|
||
/// 根据设计稿宽度计算适配后的宽度
|
||
/// - Parameters:
|
||
/// - designValue: 设计稿中的宽度值
|
||
/// - screenWidth: 当前屏幕宽度
|
||
/// - Returns: 适配后的宽度值
|
||
static func width(_ designValue: CGFloat, for screenWidth: CGFloat) -> CGFloat {
|
||
return designValue * (screenWidth / designWidth)
|
||
}
|
||
|
||
/// 根据设计稿高度计算适配后的高度
|
||
/// - Parameters:
|
||
/// - designValue: 设计稿中的高度值
|
||
/// - screenHeight: 当前屏幕高度
|
||
/// - Returns: 适配后的高度值
|
||
static func height(_ designValue: CGFloat, for screenHeight: CGFloat) -> CGFloat {
|
||
return designValue * (screenHeight / designHeight)
|
||
}
|
||
|
||
/// 根据设计稿字体大小计算适配后的字体大小
|
||
/// - Parameters:
|
||
/// - designFontSize: 设计稿中的字体大小
|
||
/// - screenWidth: 当前屏幕宽度
|
||
/// - Returns: 适配后的字体大小
|
||
static func fontSize(_ designFontSize: CGFloat, for screenWidth: CGFloat) -> CGFloat {
|
||
return designFontSize * (screenWidth / designWidth)
|
||
}
|
||
|
||
/// 计算适配比例 (基于宽度)
|
||
/// - Parameter screenWidth: 当前屏幕宽度
|
||
/// - Returns: 宽度适配比例
|
||
static func widthRatio(for screenWidth: CGFloat) -> CGFloat {
|
||
return screenWidth / designWidth
|
||
}
|
||
|
||
/// 计算适配比例 (基于高度)
|
||
/// - Parameter screenHeight: 当前屏幕高度
|
||
/// - Returns: 高度适配比例
|
||
static func heightRatio(for screenHeight: CGFloat) -> CGFloat {
|
||
return screenHeight / designHeight
|
||
}
|
||
}
|
||
|
||
// MARK: - SwiftUI View Extension
|
||
extension View {
|
||
/// 根据设计稿尺寸适配宽度
|
||
/// - Parameter designValue: 设计稿中的宽度值
|
||
/// - Returns: 带有适配宽度的视图修饰器
|
||
func adaptedWidth(_ designValue: CGFloat) -> some View {
|
||
self.modifier(AdaptedWidthModifier(designValue: designValue))
|
||
}
|
||
|
||
/// 根据设计稿尺寸适配高度
|
||
/// - Parameter designValue: 设计稿中的高度值
|
||
/// - Returns: 带有适配高度的视图修饰器
|
||
func adaptedHeight(_ designValue: CGFloat) -> some View {
|
||
self.modifier(AdaptedHeightModifier(designValue: designValue))
|
||
}
|
||
|
||
/// 根据设计稿尺寸适配字体大小
|
||
/// - Parameter designFontSize: 设计稿中的字体大小
|
||
/// - Returns: 带有适配字体的视图修饰器
|
||
func adaptedFont(_ designFontSize: CGFloat, weight: Font.Weight = .regular) -> some View {
|
||
self.modifier(AdaptedFontModifier(designFontSize: designFontSize, weight: weight))
|
||
}
|
||
}
|
||
|
||
// MARK: - ViewModifiers
|
||
struct AdaptedWidthModifier: ViewModifier {
|
||
let designValue: CGFloat
|
||
|
||
func body(content: Content) -> some View {
|
||
GeometryReader { geometry in
|
||
content
|
||
.frame(width: ScreenAdapter.width(designValue, for: geometry.size.width))
|
||
}
|
||
}
|
||
}
|
||
|
||
struct AdaptedHeightModifier: ViewModifier {
|
||
let designValue: CGFloat
|
||
|
||
func body(content: Content) -> some View {
|
||
GeometryReader { geometry in
|
||
content
|
||
.padding(.top, ScreenAdapter.height(designValue, for: geometry.size.height))
|
||
}
|
||
}
|
||
}
|
||
|
||
struct AdaptedFontModifier: ViewModifier {
|
||
let designFontSize: CGFloat
|
||
let weight: Font.Weight
|
||
|
||
func body(content: Content) -> some View {
|
||
GeometryReader { geometry in
|
||
content
|
||
.font(.system(size: ScreenAdapter.fontSize(designFontSize, for: geometry.size.width), weight: weight))
|
||
}
|
||
}
|
||
} |