
- 替换多个视图中的硬编码文本为本地化字符串,增强多语言支持。 - 修复编译错误,包括删除重复文件和修复作用域问题。 - 更新本地化文件,新增40+个本地化键值对,确保文本正确显示。 - 添加语言切换测试区域,验证文本实时更新功能。
54 lines
1.6 KiB
Swift
54 lines
1.6 KiB
Swift
import SwiftUI
|
||
|
||
/// ScreenAdapter 使用示例
|
||
/// 展示如何在 SwiftUI 视图中使用屏幕适配工具类
|
||
struct ScreenAdapterExample: View {
|
||
var body: some View {
|
||
GeometryReader { geometry in
|
||
VStack(spacing: 20) {
|
||
Text(LocalizedString("screen_adapter.method1", comment: ""))
|
||
.font(.headline)
|
||
.padding()
|
||
.background(Color.blue.opacity(0.1))
|
||
.cornerRadius(8)
|
||
|
||
Text(LocalizedString("screen_adapter.method2", comment: ""))
|
||
.font(.headline)
|
||
.padding()
|
||
.background(Color.green.opacity(0.1))
|
||
.cornerRadius(8)
|
||
|
||
Text(LocalizedString("screen_adapter.method3", comment: ""))
|
||
.font(.headline)
|
||
.padding()
|
||
.background(Color.orange.opacity(0.1))
|
||
.cornerRadius(8)
|
||
}
|
||
.padding()
|
||
}
|
||
}
|
||
}
|
||
|
||
// MARK: - 使用建议
|
||
/*
|
||
|
||
推荐使用顺序:
|
||
|
||
1. View Extension (最简洁)
|
||
.adaptedFont(16)
|
||
.adaptedHeight(20)
|
||
.adaptedWidth(100)
|
||
|
||
2. 直接调用静态方法 (灵活性高)
|
||
.font(.system(size: ScreenAdapter.fontSize(16, for: geometry.size.width)))
|
||
.padding(.top, ScreenAdapter.height(20, for: geometry.size.height))
|
||
|
||
3. 比例计算 (自定义场景)
|
||
let ratio = ScreenAdapter.heightRatio(for: geometry.size.height)
|
||
.padding(.top, 20 * ratio)
|
||
|
||
*/
|
||
|
||
#Preview {
|
||
ScreenAdapterExample()
|
||
} |