2019-03-15 13:19:19 +01:00
|
|
|
//
|
|
|
|
// CropView.swift
|
|
|
|
// CapFinder
|
|
|
|
//
|
|
|
|
// Created by User on 31.01.18.
|
|
|
|
// Copyright © 2018 User. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
2021-01-10 16:11:31 +01:00
|
|
|
//@IBDesignable
|
|
|
|
class CropView: UIView {
|
2019-03-15 13:19:19 +01:00
|
|
|
|
|
|
|
@IBInspectable var lineColor: UIColor = UIColor.black
|
|
|
|
|
|
|
|
@IBInspectable var lineWidth: Float = 2
|
|
|
|
|
|
|
|
@IBInspectable var relativeSize: Float = 0.6 {
|
|
|
|
didSet { size = CGFloat(relativeSize) / 2 }
|
|
|
|
}
|
|
|
|
|
|
|
|
private var size: CGFloat = 0.3
|
|
|
|
|
|
|
|
override init(frame: CGRect) {
|
|
|
|
super.init(frame: frame)
|
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder aDecoder: NSCoder) {
|
|
|
|
super.init(coder: aDecoder)
|
|
|
|
}
|
|
|
|
|
|
|
|
override func draw(_ rect: CGRect) {
|
|
|
|
let height = rect.height
|
|
|
|
let width = rect.width
|
|
|
|
|
|
|
|
let length = height > width ? width : height
|
|
|
|
|
|
|
|
let center = CGPoint(x: width / 2, y: height / 2)
|
|
|
|
let path = UIBezierPath()
|
|
|
|
|
|
|
|
path.lineWidth = CGFloat(self.lineWidth)
|
|
|
|
lineColor.setStroke()
|
|
|
|
|
|
|
|
path.addArc(
|
|
|
|
withCenter: center,
|
|
|
|
radius: length * size,
|
|
|
|
startAngle: 0,
|
|
|
|
endAngle: .pi * 2,
|
|
|
|
clockwise: true)
|
|
|
|
|
|
|
|
path.stroke()
|
|
|
|
}
|
|
|
|
}
|