PhotoCircleCrop
PhotoCircleCrop 是一个基于 Whatsapp 的 Swift 编写的简单圆形照片裁剪器。
要求
- iOS 8.0+
- Xcode 9+
- Swift 4
安装
PhotoCircleCrop 可以通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile 中:
pod 'PhotoCircleCrop'
PhotoCircleCrop 可以通过 Carthage 获取。要安装它,只需将以下行添加到您的 Cartfile 中:
github "scotbond/PhotoCircleCrop"
示例
要运行示例项目,请克隆仓库,然后在 Example 目录中首先运行 pod install
。
用法
要显示裁剪器,只需创建一个 CricleCropViewController
视图控制器,并传递您要裁剪的图像。
let circleCropController = CircleCropViewController()
circleCropController.image = UIImage(named: "my_photo.jpg")!
present(circleCropController, animated: true, completion: nil)
要处理裁剪操作或取消操作,你必须实现协议 CircleCropViewControllerDelegate
并设置委托
// Delegate
circleCropController.delegate = self
// MARK: - CircleCropViewControllerDelegate
func circleCropDidCancel() {
print("User canceled the crop flow")
}
func circleCropDidCropImage(_ image: UIImage) {
imageView.image = image
print("Image cropped!")
}
图片调整大小
PhotoCircleCrop 可以将裁剪后的图片调整到指定的宽度和高度。
// Set the imageSize you want to get
circleCropController.imageSize = CGSize(width: 200, height: 200)
本地化
PhotoCircleCrop 支持本地化字符串。要获取按钮标题的本地化,只需设置 selectTitle
和 cancelTitle
的值。
// 🌎 use selectTitle and cancelTitle to localize buttons
circleCropController.selectTitle = NSLocalizedString("select-button", comment: "Select")
circleCropController.cancelTitle = NSLocalizedString("cancel-button", comment: "Cancel")
依赖项
PhotoCircleCrop 基于 KACircleCropViewController
作者
Andrea Antonioni (@andrea_anto97), [email protected]
许可
PhotoCircleCrop 适用于 MIT 许可。有关更多信息,请参阅 LICENSE 文件。