MultiImageCropping is an open-source project that uses pagination to achieve multi-image cropping. It is suitable for scenarios where users publish multi-image posts, blog posts, or short videos. It guides users to crop multiple selected images to a specified aspect ratio. By default, the central area of the image is cropped and can be adjusted by moving it, making multi-image short videos more standardized and beautiful.
The MultiImageCropping SDK for iOS is available through CocoaPods.
First, install CocoaPods if you haven't already:
brew install cocoapods
pod setupAdd to your Podfile:
$iOSVersion = '11.0'
platform :ios, $iOSVersion
use_frameworks!
target 'YourProjectName' do
pod 'MultiImageCropping' # Full version with all features
endDrag the Classes folder into your project. For Objective-C projects, bridging is required.
ScreenRecording_03-29-2025.09-54-00_4.mov
originalImgs: [UIImage]- Array of original imagescropImgs: [UIImage]- Array of cropped imagesmicConfiguration: MICUIConfiguration- UI configurationmicCropConfiguration: MICCropConfiguration- Crop configurationphotoEditorVCs: [PhotoEditorViewController]- Manages multiple cropping pagescpage: Int- Current image indexdelegate: MicMultiImageCroppingControllerDelegate?- Delegate callbacks
cropImages()- Crop all original imagesconfigView()- Initialize UI componentseditImageAtPage()- Load cropping view for current pagenextPageAction()/lastPageAction()- Switch to next or previous imagecommitAction()- Submit cropping resultsresetAction()- Reset current image cropping state
MicMultiImageCroppingControllerDelegate provides the following callbacks:
micController(_:didFinishSelection:)- Returns cropped images array after completionmicController(_:nextPage:)/micController(_:lastPage:)- Page navigation callbacksmicController(didCancel:)- Callback when user cancels cropping
let images: [UIImage] = [...]
let cropConfig = MICCropConfiguration()
cropConfig.aspectRatioType = .ratio_1x1
let cropVC = MicMultiImageCroppingViewController(originalImgs: images, micCropConfiguration: cropConfig) { croppedImages in
print("Cropping completed: \(croppedImages.count) images")
}
navigationController?.pushViewController(cropVC, animated: true)MicTopMaskView/MicBottomToolView- Top mask and bottom toolbarMICUIConfiguration/MICCropConfiguration- Cropping UI and behavior configuration
This library is licensed under the MIT License.
MultiImageCropping 是一个通过分页处理来实现多图裁剪的开源项目,适用于发布多图帖子或博文或多图短视频的场景,实现引导用户将其选取的多张图片裁剪为规定比例的尺寸,默认裁剪图片中央区域,可移动调整中央区域,使多图短视频更加规范和美观。
MultiImageCropping SDK for iOS 可通过 CocoaPods 安装。
首先,如果您还没有安装 CocoaPods,请先安装:
brew install cocoapods
pod setup在 Podfile 中添加:
$iOSVersion = '11.0'
platform :ios, $iOSVersion
use_frameworks!
target 'YourProjectName' do
pod 'MultiImageCropping' # 包含所有功能的完整版本
end将 Classes 文件夹拽入项目中,OC 项目还需要桥接。
ScreenRecording_03-29-2025.09-54-00_4.mov
originalImgs: [UIImage]- 原始图片数组cropImgs: [UIImage]- 裁剪后的图片数组micConfiguration: MICUIConfiguration- UI 配置micCropConfiguration: MICCropConfiguration- 裁剪配置photoEditorVCs: [PhotoEditorViewController]- 用于管理多个裁剪页面cpage: Int- 当前裁剪的图片索引delegate: MicMultiImageCroppingControllerDelegate?- 代理回调
cropImages()- 对所有原始图片进行裁剪configView()- 初始化 UI 组件editImageAtPage()- 加载当前页的裁剪视图nextPageAction()/lastPageAction()- 切换到下一张或上一张图片commitAction()- 提交裁剪结果resetAction()- 重置当前图片裁剪状态
MicMultiImageCroppingControllerDelegate 提供以下回调:
micController(_:didFinishSelection:)- 裁剪完成后返回裁剪后的图片数组micController(_:nextPage:)/micController(_:lastPage:)- 翻页回调micController(didCancel:)- 用户取消裁剪时的回调
let images: [UIImage] = [...]
let cropConfig = MICCropConfiguration()
cropConfig.aspectRatioType = .ratio_1x1
let cropVC = MicMultiImageCroppingViewController(originalImgs: images, micCropConfiguration: cropConfig) { croppedImages in
print("裁剪完成: \(croppedImages.count) 张图片")
}
navigationController?.pushViewController(cropVC, animated: true)MicTopMaskView/MicBottomToolView- 顶部遮罩和底部工具栏MICUIConfiguration/MICCropConfiguration- 裁剪 UI 和行为配置
本项目基于 MIT License 开源协议。