CropPickerView 0.3.0

CropPickerView 0.3.0

pikachu987‘pikachu987’ 维护。



  • pikachu987

CropPickerView

CI Status Version License Platform

简介

角落和侧面按钮允许您修改裁剪和UIScrollView的位置,以缩放图像。如果图像大于UIScrollView的区域,则可以上下左右滚动图像,如果图像小于UIScrollView的区域,则图像始终居中。

CropPickerController

如果您想查看使用CropView创建的CropPickerViewController,请参阅 CropPickerController


CropPickerView

- - -
- -

要求

CropPickerView是用Swift 5.0编写的,兼容iOS 8.0以上版本。

安装

CropPickerView 可通过 CocoaPods 使用。要安装它,只需将以下行添加到您的 Podfile 中

pod 'CropPickerView'

使用方法

Xib 或 Storyboard 文件

设置

image

image

完成!




代码编辑器

import CropPickerView
let cropPickerView = CropPickerView()
self.view.addSubview(cropPickerView)

完成!




属性

图片

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)

颜色

cropPickerView.cropLineColor = UIColor.gray
cropPickerView.scrollBackgroundColor = UIColor.gray
cropPickerView.imageBackgroundColor = UIColor.gray
cropPickerView.dimBackgroundColor = UIColor(white: 0, alpha: 0.1)

缩放

cropPickerView.scrollMinimumZoomScale = 1
cropPickerView.scrollMaximumZoomScale = 2

半径

cropPickerView.radius = 50

裁剪大小

cropPickerView.cropMinSize = 200



方法

裁剪

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遵循MIT许可。更多信息请参阅LICENSE文件。