# CommonLibsFramework **Repository Path**: zhangchengcaigit_ifly_admin/common-libs-framework ## Basic Information - **Project Name**: CommonLibsFramework - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-11 - **Last Updated**: 2026-03-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # CommonLibsFramework [![CI Status](https://img.shields.io/travis/zhangchengcai/CommonLibsFramework.svg?style=flat)](https://travis-ci.org/zhangchengcai/CommonLibsFramework) [![Version](https://img.shields.io/cocoapods/v/CommonLibsFramework.svg?style=flat)](https://cocoapods.org/pods/CommonLibsFramework) [![License](https://img.shields.io/cocoapods/l/CommonLibsFramework.svg?style=flat)](https://cocoapods.org/pods/CommonLibsFramework) [![Platform](https://img.shields.io/cocoapods/p/CommonLibsFramework.svg?style=flat)](https://cocoapods.org/pods/CommonLibsFramework) ## 项目简介 CommonLibsFramework 是一个用于 iOS 项目的基础组件集合框架。该库对常用第三方库进行统一封装,并提供常见的 UI、网络、日志、路由等能力,用于减少重复代码并提升项目的模块化与开发效率。 > 注意:框架的模块名称为 `IFLYCommonKit`,在代码中需要使用 `import IFLYCommonKit` 进行导入。 ## 集成的三方库 ### 基础库 - **SnapKit** - 自动布局库 - **MBProgressHUD** - 加载指示器库 - **SDWebImage** - 图片加载库 - **SwifterSwift** - Swift 扩展库 - **CocoaLumberjack** - 日志库 - **Toast** - 提示消息库 ### Rx 系列 - **RxSwift** - 响应式编程库 - **RxCocoa** - iOS 响应式扩展 - **RxDataSources** - 表格数据源 ### UI 组件 - **MJRefresh** - 下拉刷新库 - **DTCoreText** - 富文本解析库 ### 私有库 - **IFLYNetworkManager** - 网络请求库 - **IFLYOcticons** - 图标库 - **IFLYRouter** - 路由库 ## Example To run the example project, clone the repo, and run `pod install` from the Example directory first. ## 系统要求 - iOS 16.0+ - Swift 5.7+ ## 安装 CommonLibsFramework is available through [CocoaPods](https://cocoapods.org). To install it, simply add the following line to your Podfile: ```ruby pod 'CommonLibsFramework' ``` ## 使用方法 ### 1. 初始化框架 在应用启动时初始化框架: ```swift import IFLYCommonKit // 在 AppDelegate 中初始化 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // 初始化框架 CommonLibs.shared.setup() print("CommonLibsFramework version: \(CommonLibs.version)") return true } ``` ### 2. 网络请求 #### 发送 GET 请求 ```swift NetworkService.shared.get(url: "https://jsonplaceholder.typicode.com/todos/1") { response, error in if let error = error { print("网络请求失败: \(error)") } else if let response = response { print("网络请求成功: \(response)") // 处理返回的数据 } } ``` #### 发送 POST 请求 ```swift let parameters = ["title": "Test Task", "completed": false, "userId": 1] NetworkService.shared.post(url: "https://jsonplaceholder.typicode.com/todos", parameters: parameters) { response, error in if let error = error { print("网络请求失败: \(error)") } else if let response = response { print("网络请求成功: \(response)") } } ``` #### 发送其他类型的请求 ```swift // 发送 PUT 请求 NetworkService.shared.request(url: "https://jsonplaceholder.typicode.com/todos/1", method: .put, parameters: ["title": "Updated Title"]) { response, error in // 处理响应 } // 发送 DELETE 请求 NetworkService.shared.request(url: "https://jsonplaceholder.typicode.com/todos/1", method: .delete) { response, error in // 处理响应 } ``` ### 3. 图片加载 #### 加载图片到 UIImageView ```swift let imageUrl = "https://picsum.photos/200" let placeholderImage = UIImage(named: "placeholder") ImageService.shared.loadImage(urlString: imageUrl, into: imageView, placeholder: placeholderImage) { image, error in if let error = error { print("图片加载失败: \(error)") } else if let image = image { print("图片加载成功,图片大小: \(image.size)") } } ``` #### 预加载图片 ```swift if let url = URL(string: "https://picsum.photos/200") { ImageService.shared.preloadImage(url: url) } ``` ### 4. UI 工具 #### 添加子视图并设置约束 ```swift let subview = UIView() subview.backgroundColor = .red UITools.shared.addSubview(subview, to: self.view) { make in make.centerX.equalToSuperview() make.centerY.equalToSuperview() make.width.height.equalTo(100) } ``` #### 显示和隐藏加载指示器 ```swift // 显示加载指示器 let hud = UITools.shared.showHUD(in: self.view, message: "加载中...") // 模拟网络请求 DispatchQueue.main.asyncAfter(deadline: .now() + 2) { // 隐藏加载指示器 UITools.shared.hideHUD(in: self.view) } ``` #### 显示提示消息 ```swift // 显示成功提示 UITools.shared.showToast(message: "操作成功", in: self.view) // 显示错误提示 UITools.shared.showToast(message: "操作失败", in: self.view) // 自定义显示时长 UITools.shared.showToast(message: "提示信息", in: self.view, duration: 3.0) ``` ## 常见问题 ### 1. 依赖冲突 如果项目中已经使用了相同的三方库,可能会出现依赖冲突。可以在 Podfile 中指定版本号来解决冲突: ```ruby # 基础库 pod 'SnapKit', '~> 5.7.1' pod 'MBProgressHUD', '~> 2.1.7' pod 'SDWebImage', '~> 5.21.7' pod 'SwifterSwift', '~> 8.0.0' pod 'CocoaLumberjack', '~> 3.9.0' pod 'Toast' # Rx 系列 pod 'RxSwift', '~> 6.9.0' pod 'RxCocoa', '~> 6.9.0' pod 'RxDataSources', '~> 5.0.0' # UI 组件 pod 'MJRefresh', '~> 3.7.9' pod 'DTCoreText', '~> 1.6.28' # 私有库 pod 'IFLYNetworkManager', '~> 1.1.88' pod 'IFLYOcticons', '~> 1.1.7' pod 'IFLYRouter', '~> 1.1.1' # 框架本身 pod 'CommonLibsFramework' ``` ### 2. 最低 iOS 版本要求 CommonLibsFramework 要求 iOS 16.0+,如果项目需要支持更低版本的 iOS,可以修改 podspec 文件中的部署目标。 ## 贡献指南 欢迎贡献代码和提出问题!如果您有任何改进建议或发现了 bug,请提交 issue 或 pull request。 ## Author zhangchengcai, zhangchengcai3615@126.com ## License CommonLibsFramework is available under the MIT license. See the LICENSE file for more info.