Files
e-party-iOS/yana/Views/Components/UserAgreementView.swift
edwinQQQ 30c3e530fb feat: 增强多语言支持与本地化功能
- 新增多语言问题修复计划文档,详细描述了多语言支持的现状与解决方案。
- 在LocalizationManager中启用全局本地化方法,替换多个视图中的NSLocalizedString调用为LocalizedString。
- 更新MainFeature以确保在MeView标签页时正确加载用户数据。
- 在多个视图中添加语言切换测试区域,确保文本实时更新。
- 修复MeView显示问题,确保用户信息和动态内容正确加载。
2025-07-28 18:28:24 +08:00

89 lines
3.3 KiB
Swift

import SwiftUI
// MARK: - User Agreement View Component
struct UserAgreementView: View {
@Binding var isAgreed: Bool
let onUserServiceTapped: () -> Void
let onPrivacyPolicyTapped: () -> Void
var body: some View {
HStack(alignment: .center, spacing: 12) {
//
Button(action: {
isAgreed.toggle()
}) {
Image(systemName: isAgreed ? "checkmark.circle.fill" : "circle")
.font(.system(size: 22))
.foregroundColor(isAgreed ? Color(hex: 0x8A4FFF) : Color(hex: 0x666666))
}
//
Text(createAttributedText())
.font(.system(size: 14))
.multilineTextAlignment(.leading)
.environment(\.openURL, OpenURLAction { url in
if url.absoluteString == "user-service-agreement" {
onUserServiceTapped()
return .handled
} else if url.absoluteString == "privacy-policy" {
onPrivacyPolicyTapped()
return .handled
}
return .systemAction
})
}
.frame(maxWidth: .infinity) //
.padding(.horizontal, 29) //
}
// MARK: - Private Methods
private func createAttributedText() -> AttributedString {
var attributedString = AttributedString(LocalizedString("login.agreement_policy", comment: ""))
//
attributedString.foregroundColor = Color(hex: 0x666666)
// ""
if let userServiceRange = attributedString.range(of: LocalizedString("login.agreement", comment: "")) {
attributedString[userServiceRange].foregroundColor = Color(hex: 0x8A4FFF)
attributedString[userServiceRange].underlineStyle = .single
attributedString[userServiceRange].link = URL(string: "user-service-agreement")
}
// ""
if let privacyPolicyRange = attributedString.range(of: LocalizedString("login.policy", comment: "")) {
attributedString[privacyPolicyRange].foregroundColor = Color(hex: 0x8A4FFF)
attributedString[privacyPolicyRange].underlineStyle = .single
attributedString[privacyPolicyRange].link = URL(string: "privacy-policy")
}
return attributedString
}
}
//#Preview {
// VStack(spacing: 20) {
// UserAgreementView(
// isAgreed: .constant(true),
// onUserServiceTapped: {
// debugInfoSync("User Service Agreement tapped")
// },
// onPrivacyPolicyTapped: {
// debugInfoSync("Privacy Policy tapped")
// }
// )
//
// UserAgreementView(
// isAgreed: .constant(true),
// onUserServiceTapped: {
// debugInfoSync("User Service Agreement tapped")
// },
// onPrivacyPolicyTapped: {
// debugInfoSync("Privacy Policy tapped")
// }
// )
// }
// .padding()
// .background(Color.gray.opacity(0.1))
//}