qchenqizhi / QCropper

Image cropping/rotating/straightening library for iOS in Swift
MIT License
268 stars 51 forks source link

How can custom the toolbar? Would you help me to do this feature? Many thanks! #6

Closed thuongvanbui39 closed 3 years ago

qchenqizhi commented 3 years ago

You can do this by override toolbar, but the height of this toolbar is immutable.

class CustomCropperViewController: CropperViewController {

    override var toolbar: UIView {
        get {
            return customToolbar
        }
        set {
            customToolbar = newValue
        }
    }

    lazy var customToolbar: UIView = {
        let v = UIView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.safeAreaInsets.bottom + 44))
        v.backgroundColor = .red

        let button = UIButton(frame: CGRect(x: 100, y: 0, width: 200, height: 44))
        button.addTarget(self, action: #selector(button1Pressed(_:)), for: .touchUpInside)
        button.setTitle("ButtonTitle", for: .normal)
        button.setTitleColor(.white, for: .normal)
        button.titleLabel?.font = .systemFont(ofSize: 20)

        v.addSubview(button)

        return v
    }()

    @objc func button1Pressed(_ sender: UIButton) {
        self.rotate90degrees()
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        isCropBoxPanEnabled = false
        topBar.isHidden = true
        angleRuler.isHidden = true
        aspectRatioPicker.isHidden = true
    }

    override func resetToDefaultLayout() {
        super.resetToDefaultLayout()

        aspectRatioLocked = true
        setAspectRatioValue(1.2)
    }
}

If you need more custom UI, you need to directly modify the code of CropperViewController

thuongvanbui39 commented 3 years ago

Thank uuuuu <3

thuongvanbui39 commented 3 years ago
Screen Shot 2021-04-12 at 09 39 21

I don't find the properties to set aspect ratio like the above image in our lib. Could you help me?