
- 创建SettingPage视图,包含用户信息管理、头像设置、昵称编辑等功能。 - 实现SettingViewModel,处理设置页面的业务逻辑,包括头像上传、昵称更新等。 - 添加相机和相册选择功能,支持头像更换。 - 更新MainPage和MainViewModel,添加导航逻辑以支持设置页面的访问。 - 完善本地化支持,确保多语言兼容性。 - 新增相关测试建议,确保功能完整性和用户体验。
56 lines
1.7 KiB
Swift
56 lines
1.7 KiB
Swift
import SwiftUI
|
|
import SafariServices
|
|
|
|
// MARK: - Web View Component
|
|
struct WebView: UIViewControllerRepresentable {
|
|
let url: URL
|
|
|
|
func makeUIViewController(context: Context) -> SFSafariViewController {
|
|
let config = SFSafariViewController.Configuration()
|
|
config.entersReaderIfAvailable = false
|
|
config.barCollapsingEnabled = true
|
|
|
|
let safariViewController = SFSafariViewController(url: url, configuration: config)
|
|
safariViewController.preferredBarTintColor = UIColor.systemBackground
|
|
safariViewController.preferredControlTintColor = UIColor.systemBlue
|
|
|
|
return safariViewController
|
|
}
|
|
|
|
func updateUIViewController(_ uiViewController: SFSafariViewController, context: Context) {
|
|
// Safari View Controller 不需要更新
|
|
}
|
|
}
|
|
|
|
// MARK: - Web View Modifier
|
|
extension View {
|
|
/// 显示 Web 页面的修饰符
|
|
/// - Parameters:
|
|
/// - isPresented: 是否显示的绑定变量
|
|
/// - url: 要显示的 URL
|
|
/// - Returns: 修饰后的视图
|
|
func webView(isPresented: Binding<Bool>, url: URL?) -> some View {
|
|
self.sheet(isPresented: isPresented) {
|
|
if let url = url {
|
|
WebView(url: url)
|
|
} else {
|
|
Text(LocalizedString("web_view.load_failed", comment: ""))
|
|
.foregroundColor(.red)
|
|
.padding()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//#Preview {
|
|
// VStack {
|
|
// Button(LocalizedString("web_view.open_webpage", comment: "")) {
|
|
// // 预览时不执行任何操作
|
|
// }
|
|
// }
|
|
// .webView(
|
|
// isPresented: .constant(true),
|
|
// url: URL(string: "https://www.apple.com")
|
|
// )
|
|
//}
|