|
1 | 1 | # UIImageCropper
|
2 | 2 |
|
| 3 | +Simple Image cropper for UIImagePickerController with customisable crop aspect ratio. Made purely with Swift 4! |
| 4 | + |
| 5 | +Replaces the iOS "crop only to square" functionality. Easy few line setup with delegate method/s. |
| 6 | + |
| 7 | +## Requirements |
| 8 | + |
| 9 | +- iOS10+ |
| 10 | +- Xcode 9.2+ |
| 11 | +- Swift 4 |
| 12 | + |
| 13 | + |
| 14 | +## Install |
| 15 | +UIImageCropper is available through [CocoaPods](http://cocoapods.org). To install |
| 16 | +it, simply add the following line to your Podfile: |
| 17 | + |
| 18 | +``` |
| 19 | +pod 'UIImageCropper' |
| 20 | +``` |
| 21 | + |
| 22 | + (or add UIImageCropper folder to your project) |
| 23 | + |
| 24 | +## Usage |
| 25 | + |
| 26 | +Import the pod |
| 27 | + |
| 28 | +``` |
| 29 | +import UIImageCropper |
| 30 | +``` |
| 31 | + |
| 32 | +Create instanses of UIImagePickerController and UIImageCropper |
| 33 | + |
| 34 | +UIImageCropper can take ```cropRatio``` as parameter. Default ratio is 1 (square). |
| 35 | + |
| 36 | +``` |
| 37 | +let picker = UIImagePickerController() |
| 38 | +let cropper = UIImageCropper(cropRatio: 2/3) |
| 39 | +``` |
| 40 | + |
| 41 | +Setup UIImageCropper |
| 42 | + |
| 43 | +``` |
| 44 | +cropper.picker = picker |
| 45 | +cropper.delegate = self |
| 46 | +//cropper.cropRatio = 2/3 //(can be set during runtime or in init) |
| 47 | +``` |
| 48 | + |
| 49 | +Implement ```UIImageCropperProtocol```delegate method/s |
| 50 | + |
| 51 | +``` |
| 52 | +func didCropImage(originalImage: UIImage?, croppedImage: UIImage?) { |
| 53 | + imageView.image = croppedImage |
| 54 | +} |
| 55 | +
|
| 56 | +//optional (if not implemented cropper will close itself and picker) |
| 57 | +func didCancel() { |
| 58 | + picker.dismiss(animated: true, completion: nil) |
| 59 | +} |
| 60 | +
|
| 61 | +``` |
| 62 | + |
| 63 | +The UIImageCropper will handle the image picking (delegate methods). To start image picking just present the UIImagePickerController instance. |
| 64 | + |
| 65 | +``` |
| 66 | +self.present(self.picker, animated: true, completion: nil) |
| 67 | +``` |
| 68 | + |
| 69 | +For full usage exmaple see **CropperExample** in Example folder. |
| 70 | + |
| 71 | +## Coming soon |
| 72 | + |
| 73 | +* Possibility to use cropper without UIImagePickerController |
| 74 | + |
| 75 | +## Issues and contribution |
| 76 | + |
| 77 | +If you find any issues please add and issue to this repository. |
| 78 | + |
| 79 | +Improvements and/or fixes as pull requests are more than welcome. |
3 | 80 |
|
4 | 81 | ## Author
|
5 | 82 |
|
|
0 commit comments