PhotoCircleCrop is a simple circular photo cropper writter in Swift, based on Whatsapp.
- iOS 8.0+
- Xcode 9+
- Swift 4
PhotoCircleCrop is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'PhotoCircleCrop'
PhotoCircleCrop is available through Carthage. To install it, simply add the following line to your Cartfile:
github "scotbond/PhotoCircleCrop"
To run the example project, clone the repo, and run pod install
from the Example directory first.
To show the cropper you have just to create a CricleCropViewController
view controller and pass it the image you want to crop.
let circleCropController = CircleCropViewController()
circleCropController.image = UIImage(named: "my_photo.jpg")!
present(circleCropController, animated: true, completion: nil)
To handle the crop action or the cancel action, you have to implement the protocol CircleCropViewControllerDelegate
and set the delegate
// 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 can resize the cropped image to a specific width and height.
// Set the imageSize you want to get
circleCropController.imageSize = CGSize(width: 200, height: 200)
PhotoCircleCrop support localized strings. To get button titles localized, just sets a value to selectTitle
and cancelTitle
// 🌎 use selectTitle and cancelTitle to localize buttons
circleCropController.selectTitle = NSLocalizedString("select-button", comment: "Select")
circleCropController.cancelTitle = NSLocalizedString("cancel-button", comment: "Cancel")
PhotoCircleCrop is base on KACircleCropViewController
Andrea Antonioni (@andrea_anto97), andreaantonioni97@gmail.com
PhotoCircleCrop is available under the MIT license. See the LICENSE file for more info.