The Corner and Side buttons allow you to modify the position of the crop and UIScrollView to zoom the image. If the image is larger than the area of the UIScrollView, the image can be scrolled up and down, left and right, and if the image is smaller than the area of the UIScrollView, the image is always centered.
If you want to see the CropPickerViewController that is created with CropView, see CropPickerController
- | - |
---|---|
![]() |
![]() |
![]() |
![]() |
- | - |
---|---|
![]() |
![]() |
CropPickerView
written in Swift 5.0. Compatible with iOS 8.0+
CropPickerView is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'CropPickerView'
setting
done!
import CropPickerView
let cropPickerView = CropPickerView()
self.view.addSubview(cropPickerView)
done!
image
cropPickerView.image = image
cropPickerView.image(image, crop: CGRect(x: 50, y: 30, width: 100, height: 80), isRealCropRect: false)
cropPickerView.image(image, crop: CGRect(x: 50, y: 30, width: 100, height: 80), isRealCropRect: true)
cropPickerView.image(image, isMin: false, crop: CGRect(x: 50, y: 30, width: 100, height: 80), isRealCropRect: true)
cropPickerView.image(image, isMin: false)
color
cropPickerView.cropLineColor = UIColor.gray
cropPickerView.scrollBackgroundColor = UIColor.gray
cropPickerView.imageBackgroundColor = UIColor.gray
cropPickerView.dimBackgroundColor = UIColor(white: 0, alpha: 0.1)
zoom
cropPickerView.scrollMinimumZoomScale = 1
cropPickerView.scrollMaximumZoomScale = 2
radius
cropPickerView.radius = 50
aspectRatio (square)
// free
cropPickerView.aspectRatio = 0
// square
cropPickerView.aspectRatio = 1
// width : height = 1 : 2
cropPickerView.aspectRatio = 1 / 2
// width : height = 3 : 4
cropPickerView.aspectRatio = 3 / 4
// width : height = 4 : 3
cropPickerView.aspectRatio = 4 / 3
cropSize
cropPickerView.cropMinSize = 200
isTransparent
cropPickerView.isTransparent = true
crop
cropPickerView.crop { (result) in
if let error = (result.error as NSError?) {
let alertController = UIAlertController(title: "Error", message: error.domain, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil))
self.present(alertController, animated: true, completion: nil)
return
}
self.imageView.image = result.image
}
class ViewController: UIViewController{
override func viewDidLoad() {
super.viewDidLoad()
let cropPickerView = CropPickerView()
cropPickerView.delegate = self
}
}
// MARK: CropPickerViewDelegate
extension ViewController: CropPickerViewDelegate {
func cropPickerView(_ cropPickerView: CropPickerView, result: CropResult) {
}
func cropPickerView(_ cropPickerView: CropPickerView, didChange frame: CGRect) {
print("frame: \(frame)")
}
}
pikachu987, [email protected]
CropPickerView is available under the MIT license. See the LICENSE file for more info.