Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Pod/Classes/EPExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ extension UIViewController {
showAlert(message, andTitle: "")
}

func showAlert(_ message: String, andTitle title: String) {
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
public func showAlert(_ message: String, andTitle title: String) {
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertController.Style.alert)

// add an action (button)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))

// show the alert
self.present(alert, animated: true, completion: nil)
Expand Down
27 changes: 20 additions & 7 deletions Pod/Classes/EPSignatureView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ open class EPSignatureView: UIView {
fileprivate var bezierCounter : Int = 0

// MARK: - Public Vars

open var strokeColor: UIColor {
if #available(iOS 13.0, *) {
return UIColor.label
}
return UIColor.black
}

open var strokeColor = UIColor.black
open var strokeWidth: CGFloat = 2.0 {
didSet { bezierPath.lineWidth = strokeWidth }
}
Expand Down Expand Up @@ -116,10 +122,17 @@ open class EPSignatureView: UIView {
/** scales and repositions the path
*/
open func reposition() {
var ratio = min(self.bounds.width / bezierPath.bounds.width, 1)
ratio = min((self.bounds.height - 64) / bezierPath.bounds.height, ratio)
bezierPath.apply(CGAffineTransform(scaleX: ratio, y: ratio))
setNeedsDisplay()
if !bezierPath.isEmpty {
var ratio = min(self.bounds.width / bezierPath.bounds.width, 1)
ratio = min((self.bounds.height - 64) / bezierPath.bounds.height, ratio)
bezierPath.apply(CGAffineTransform(scaleX: ratio, y: ratio))
let midX = (self.bounds.width - bezierPath.bounds.width) / 2
let midY = (self.bounds.height - bezierPath.bounds.height) / 2
let translateX = -bezierPath.bounds.origin.x + midX
let translateY = -bezierPath.bounds.origin.y + midY
bezierPath.apply(CGAffineTransform(translationX: translateX, y: translateY))
setNeedsDisplay()
}
}

/** Returns the drawn path as Image. Adding subview to this view will also get returned in this image.
Expand All @@ -137,7 +150,7 @@ open class EPSignatureView: UIView {

/** Returns the rect of signature image drawn in the canvas. This can very very useful in croping out the unwanted empty areas in the signature image returned.
*/

open func getSignatureBoundsInCanvas() -> CGRect {
return bezierPath.bounds
}
Expand All @@ -149,7 +162,7 @@ open class EPSignatureView: UIView {
NSKeyedArchiver.archiveRootObject(bezierPath, toFile: localPath)
}
}

open func loadSignature(_ filePath: String) {
if let path = getPath(filePath) {
isSigned = true
Expand Down
40 changes: 21 additions & 19 deletions Pod/Classes/EPSignatureViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ open class EPSignatureViewController: UIViewController {

// MARK: - IBOutlets

@IBOutlet weak var switchSaveSignature: UISwitch!
@IBOutlet weak var lblSignatureSubtitle: UILabel!
@IBOutlet weak var lblDefaultSignature: UILabel!
@IBOutlet public weak var lblTitle: UILabel!
@IBOutlet public weak var switchSaveSignature: UISwitch!
@IBOutlet public weak var lblSignatureSubtitle: UILabel!
@IBOutlet public weak var lblDefaultSignature: UILabel!
@IBOutlet weak var lblDate: UILabel!
@IBOutlet weak var viewMargin: UIView!
@IBOutlet weak var lblX: UILabel!
@IBOutlet weak var signatureView: EPSignatureView!
@IBOutlet public weak var lblX: UILabel!
@IBOutlet public weak var signatureView: EPSignatureView!

// MARK: - Public Vars

Expand All @@ -39,14 +40,14 @@ open class EPSignatureViewController: UIViewController {
override open func viewDidLoad() {
super.viewDidLoad()

let cancelButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.cancel, target: self, action: #selector(EPSignatureViewController.onTouchCancelButton))
cancelButton.tintColor = tintColor
self.navigationItem.leftBarButtonItem = cancelButton
let cancelButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.cancel, target: self, action: #selector(EPSignatureViewController.onTouchCancelButton))
// cancelButton.tintColor = tintColor
// self.navigationItem.leftBarButtonItem = cancelButton

let doneButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.done, target: self, action: #selector(EPSignatureViewController.onTouchDoneButton))
doneButton.tintColor = tintColor
let clearButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.trash, target: self, action: #selector(EPSignatureViewController.onTouchClearButton))
clearButton.tintColor = tintColor
let doneButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.done, target: self, action: #selector(EPSignatureViewController.onTouchDoneButton))
// doneButton.tintColor = tintColor
let clearButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.trash, target: self, action: #selector(EPSignatureViewController.onTouchClearButton))
// clearButton.tintColor = tintColor

if showsDate {
let dateFormatter = DateFormatter()
Expand All @@ -58,8 +59,8 @@ open class EPSignatureViewController: UIViewController {
}

if showsSaveSignatureOption {
let actionButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.action, target: self, action: #selector(EPSignatureViewController.onTouchActionButton(_:)))
actionButton.tintColor = tintColor
let actionButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.action, target: self, action: #selector(EPSignatureViewController.onTouchActionButton(_:)))
// actionButton.tintColor = tintColor
self.navigationItem.rightBarButtonItems = [doneButton, clearButton, actionButton]
switchSaveSignature.onTintColor = tintColor
} else {
Expand Down Expand Up @@ -106,7 +107,8 @@ open class EPSignatureViewController: UIViewController {
dismiss(animated: true, completion: nil)
}

@objc func onTouchDoneButton() {
@objc
open func onTouchDoneButton() {
if let signature = signatureView.getSignatureAsImage() {
if switchSaveSignature.isOn {
let docPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first
Expand All @@ -121,20 +123,20 @@ open class EPSignatureViewController: UIViewController {
}

@objc func onTouchActionButton(_ barButton: UIBarButtonItem) {
let action = UIAlertController(title: "Action", message: "", preferredStyle: UIAlertControllerStyle.actionSheet)
let action = UIAlertController(title: "Action", message: "", preferredStyle: UIAlertController.Style.actionSheet)
action.view.tintColor = tintColor

action.addAction(UIAlertAction(title: "Load default signature", style: UIAlertActionStyle.default, handler: { action in
action.addAction(UIAlertAction(title: "Load default signature", style: UIAlertAction.Style.default, handler: { action in
let docPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first
let filePath = (docPath! as NSString).appendingPathComponent("sig.data")
self.signatureView.loadSignature(filePath)
}))

action.addAction(UIAlertAction(title: "Delete default signature", style: UIAlertActionStyle.destructive, handler: { action in
action.addAction(UIAlertAction(title: "Delete default signature", style: UIAlertAction.Style.destructive, handler: { action in
self.signatureView.removeSignature()
}))

action.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil))
action.addAction(UIAlertAction(title: "Cancel", style: UIAlertAction.Style.cancel, handler: nil))

if let popOver = action.popoverPresentationController {
popOver.barButtonItem = barButton
Expand Down
Loading