diff --git a/README.md b/README.md index 140d257..3e5787d 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,11 @@ YPDrawSignatureView is available under the MIT license. See the [LICENSE](LICENS ## Update history -### v1.1 - 5/3/17 +### v1.1.1 - 5/23/17 + +* Bugfix + +#### v1.1 - 5/3/17 * Added PDF support for exporting signature as high resolution vector graphics * Deprecated methods and properties are properly marked diff --git a/SignatureTest/SignatureTest/AppDelegate.swift b/SignatureTest/SignatureTest/AppDelegate.swift index 52d49f1..952aa2f 100644 --- a/SignatureTest/SignatureTest/AppDelegate.swift +++ b/SignatureTest/SignatureTest/AppDelegate.swift @@ -1,5 +1,5 @@ // YPDrawSignatureView is open source -// Version 1.1 +// Version 1.1.1 // // Copyright (c) 2014 - 2017 The YPDrawSignatureView Project Contributors // Available under the MIT license diff --git a/SignatureTest/SignatureTest/Base.lproj/Main.storyboard b/SignatureTest/SignatureTest/Base.lproj/Main.storyboard index 1fed66e..be00631 100644 --- a/SignatureTest/SignatureTest/Base.lproj/Main.storyboard +++ b/SignatureTest/SignatureTest/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - + @@ -31,6 +31,11 @@ + + + + + diff --git a/SignatureTest/SignatureTest/ViewController.swift b/SignatureTest/SignatureTest/ViewController.swift index 7587882..e61854d 100644 --- a/SignatureTest/SignatureTest/ViewController.swift +++ b/SignatureTest/SignatureTest/ViewController.swift @@ -1,5 +1,5 @@ // YPDrawSignatureView is open source -// Version 1.1 +// Version 1.1.1 // // Copyright (c) 2014 - 2017 The YPDrawSignatureView Project Contributors // Available under the MIT license diff --git a/SignatureTest/SignatureTest/YPDrawSignatureView.swift b/SignatureTest/SignatureTest/YPDrawSignatureView.swift index a2823c3..5557026 100644 --- a/SignatureTest/SignatureTest/YPDrawSignatureView.swift +++ b/SignatureTest/SignatureTest/YPDrawSignatureView.swift @@ -1,5 +1,5 @@ // YPDrawSignatureView is open source -// Version 1.1 +// Version 1.1.1 // // Copyright (c) 2014 - 2017 The YPDrawSignatureView Project Contributors // Available under the MIT license @@ -32,13 +32,13 @@ final public class YPDrawSignatureView: UIView { // MARK: - Public properties @IBInspectable public var strokeWidth: CGFloat = 2.0 { didSet { - self.path.lineWidth = strokeWidth + path.lineWidth = strokeWidth } } @IBInspectable public var strokeColor: UIColor = .black { didSet { - self.strokeColor.setStroke() + strokeColor.setStroke() } } @@ -46,14 +46,14 @@ final public class YPDrawSignatureView: UIView { @available(*, deprecated, renamed: "backgroundColor") @IBInspectable public var signatureBackgroundColor: UIColor = .white { didSet { - self.backgroundColor = signatureBackgroundColor + backgroundColor = signatureBackgroundColor } } // Computed Property returns true if the view actually contains a signature public var doesContainSignature: Bool { get { - if self.path.isEmpty { + if path.isEmpty { return false } else { return true @@ -70,15 +70,15 @@ final public class YPDrawSignatureView: UIView { required public init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) - self.path.lineWidth = self.strokeWidth - self.path.lineJoinStyle = CGLineJoin.round + path.lineWidth = strokeWidth + path.lineJoinStyle = CGLineJoin.round } override public init(frame: CGRect) { super.init(frame: frame) - self.path.lineWidth = self.strokeWidth - self.path.lineJoinStyle = CGLineJoin.round + path.lineWidth = strokeWidth + path.lineJoinStyle = CGLineJoin.round } // MARK: - Draw @@ -91,11 +91,11 @@ final public class YPDrawSignatureView: UIView { override public func touchesBegan(_ touches: Set , with event: UIEvent?) { if let firstTouch = touches.first { let touchPoint = firstTouch.location(in: self) - self.controlPoint = 0 - self.points[0] = touchPoint + controlPoint = 0 + points[0] = touchPoint } - if let delegate = self.delegate { + if let delegate = delegate { delegate.didStart() } } @@ -103,34 +103,34 @@ final public class YPDrawSignatureView: UIView { override public func touchesMoved(_ touches: Set , with event: UIEvent?) { if let firstTouch = touches.first { let touchPoint = firstTouch.location(in: self) - self.controlPoint += 1 - self.points[self.controlPoint] = touchPoint - if (self.controlPoint == 4) { - self.points[3] = CGPoint(x: (self.points[2].x + self.points[4].x)/2.0, y: (self.points[2].y + self.points[4].y)/2.0) - self.path.move(to: self.points[0]) - self.path.addCurve(to: self.points[3], controlPoint1:self.points[1], controlPoint2:self.points[2]) + controlPoint += 1 + points[controlPoint] = touchPoint + if (controlPoint == 4) { + points[3] = CGPoint(x: (points[2].x + points[4].x)/2.0, y: (points[2].y + points[4].y)/2.0) + path.move(to: points[0]) + path.addCurve(to: points[3], controlPoint1: points[1], controlPoint2: points[2]) - self.setNeedsDisplay() - self.points[0] = self.points[3] - self.points[1] = self.points[4] - self.controlPoint = 1 + setNeedsDisplay() + points[0] = points[3] + points[1] = points[4] + controlPoint = 1 } - self.setNeedsDisplay() + setNeedsDisplay() } } override public func touchesEnded(_ touches: Set , with event: UIEvent?) { - if self.controlPoint < 4 { - let touchPoint = self.points[0] - self.path.move(to: CGPoint(x: touchPoint.x-1.0,y: touchPoint.y)) - self.path.addLine(to: CGPoint(x: touchPoint.x+1.0,y: touchPoint.y)) - self.setNeedsDisplay() + if controlPoint < 4 { + let touchPoint = points[0] + path.move(to: CGPoint(x: touchPoint.x-1.0,y: touchPoint.y)) + path.addLine(to: CGPoint(x: touchPoint.x+1.0,y: touchPoint.y)) + setNeedsDisplay() } else { - self.controlPoint = 0 + controlPoint = 0 } - if let delegate = self.delegate { + if let delegate = delegate { delegate.didFinish() } } @@ -147,6 +147,7 @@ final public class YPDrawSignatureView: UIView { public func getSignature(scale:CGFloat = 1) -> UIImage? { if !doesContainSignature { return nil } UIGraphicsBeginImageContextWithOptions(self.bounds.size, false, scale) + self.strokeColor.setStroke() self.path.stroke() let signature = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() @@ -179,14 +180,15 @@ final public class YPDrawSignatureView: UIView { guard let dataConsumer = CGDataConsumer.init(data: mutableData!) else { fatalError() } - var rect = CGRect(x: 0, y: 0, width: self.frame.width, height: self.frame.height) + var rect = CGRect(x: 0, y: 0, width: frame.width, height: frame.height) guard let pdfContext = CGContext(consumer: dataConsumer, mediaBox: &rect, nil) else { fatalError() } pdfContext.beginPDFPage(nil) - pdfContext.translateBy(x: 0, y: self.frame.height) + pdfContext.translateBy(x: 0, y: frame.height) pdfContext.scaleBy(x: 1, y: -1) - pdfContext.addPath(self.path.cgPath) + pdfContext.addPath(path.cgPath) + pdfContext.setStrokeColor(strokeColor.cgColor) pdfContext.strokePath() pdfContext.saveGState() pdfContext.endPDFPage() diff --git a/SignatureTest/SignatureTestTests/SignatureViewTest.swift b/SignatureTest/SignatureTestTests/SignatureViewTest.swift index 6a068f8..f3daf20 100644 --- a/SignatureTest/SignatureTestTests/SignatureViewTest.swift +++ b/SignatureTest/SignatureTestTests/SignatureViewTest.swift @@ -1,5 +1,5 @@ // YPDrawSignatureView is open source -// Version 1.0.2 +// Version 1.1.1 // // Copyright (c) 2014 - 2017 The YPDrawSignatureView Project Contributors // Available under the MIT license @@ -39,7 +39,7 @@ class SignatureViewTest: XCTestCase { signatureView.strokeColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0) signatureView.injectBezierPath(doodle()) signatureView.draw(signatureView.frame) - XCTAssertNotEqual(signatureView.signatureBackgroundColor, getPixelColor(view2Image(signatureView), at: CGPoint(x: 4, y: 4))) + XCTAssertNotEqual(signatureView.backgroundColor, getPixelColor(view2Image(signatureView), at: CGPoint(x: 4, y: 4))) } func testGetSignature() { @@ -49,7 +49,7 @@ class SignatureViewTest: XCTestCase { signatureView.draw(signatureView.frame) let signature = signatureView.getSignature() - XCTAssertNotEqual(signatureView.signatureBackgroundColor, getPixelColor(signature!, at: CGPoint(x: 4, y: 4))) + XCTAssertNotEqual(signatureView.backgroundColor, getPixelColor(signature!, at: CGPoint(x: 4, y: 4))) } diff --git a/SignatureTest/SignatureTestUITests/SignatureTestUITests.swift b/SignatureTest/SignatureTestUITests/SignatureTestUITests.swift index 2c45bcb..ca8f1a3 100644 --- a/SignatureTest/SignatureTestUITests/SignatureTestUITests.swift +++ b/SignatureTest/SignatureTestUITests/SignatureTestUITests.swift @@ -1,10 +1,11 @@ +// YPDrawSignatureView is open source +// Version 1.1.1 // -// SignatureTestUITests.swift -// SignatureTestUITests -// -// Created by Geert-Jan Korsbø Nilsen on 19/12/15. -// Copyright © 2015 Yuppielabel. All rights reserved. +// Copyright (c) 2014 - 2017 The YPDrawSignatureView Project Contributors +// Available under the MIT license // +// https://github.com/GJNilsen/YPDrawSignatureView/blob/master/LICENSE License Information +// https://github.com/GJNilsen/YPDrawSignatureView/blob/master/README.md Project Contributors import XCTest diff --git a/Sources/YPDrawSignatureView.swift b/Sources/YPDrawSignatureView.swift index ee666ae..cc40e91 100644 --- a/Sources/YPDrawSignatureView.swift +++ b/Sources/YPDrawSignatureView.swift @@ -1,5 +1,5 @@ // YPDrawSignatureView is open source -// Version 1.1 +// Version 1.1.1 // // Copyright (c) 2014 - 2017 The YPDrawSignatureView Project Contributors // Available under the MIT license @@ -147,6 +147,7 @@ final public class YPDrawSignatureView: UIView { public func getSignature(scale:CGFloat = 1) -> UIImage? { if !doesContainSignature { return nil } UIGraphicsBeginImageContextWithOptions(self.bounds.size, false, scale) + self.strokeColor.setStroke() self.path.stroke() let signature = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() @@ -187,6 +188,7 @@ final public class YPDrawSignatureView: UIView { pdfContext.translateBy(x: 0, y: self.frame.height) pdfContext.scaleBy(x: 1, y: -1) pdfContext.addPath(self.path.cgPath) + pdfContext.setStrokeColor(strokeColor.cgColor) pdfContext.strokePath() pdfContext.saveGState() pdfContext.endPDFPage()