Skip to content

Commit

Permalink
Added support for Vector Graphics
Browse files Browse the repository at this point in the history
Deprecated some functions and properties
  • Loading branch information
GJNilsen committed May 3, 2017
1 parent 19ac325 commit a415fae
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 76 deletions.
92 changes: 59 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Simple class for capturing signatures.


## Swift 3

The class supports Swift 3.
Expand All @@ -10,6 +11,7 @@ This branch is not backwards compatible, please download the previous release if
- Swift 3.0 will be supported
- Swift 2.3 will not be supported


## Usage

Add a new `UIView` where you want the signature capture field. Set its class to `YPDrawSignatureView`, and connect it to an `@IBOutlet` property in your `UIViewController`. For saving and clearing the signature, add two buttons to your view controller. Hook each button up to an `@IBAction` function.
Expand All @@ -18,19 +20,28 @@ Add a new `UIView` where you want the signature capture field. Set its class to

With the view selected, choose the IB Attributes Inspector panel to set custom values, or set them in code where you initialise the signature view.


## New Feature

On ground of popular demand, added signature export as Vector Path in PDF Data Format.


#### Methods

* `clear()`

This clears the view
Clears signature

* `getSignature()`

This returns the signature with the bounds of the view
Returns signature with bounds of YPDrawSignatureView instance

* `getCroppedSignature()`

This returns the signature with the bounds of the signature
Returns signature with bounds of signature

* ̀getPDFSignature()`
Returns signature as Vector Path PDF Data Format

#### Properties

Expand All @@ -46,18 +57,13 @@ Sets the width of the signature stroke

Sets the UIColor of the signature stroke

* `signatureBackgroundColor: UIColor`

Sets the background UIColor of the view

#### Optional Protocol Methods

* `startedDrawing()` // Deprecated
* `didStart()`

Notifies the delegate when someone starts a stroke in the view

* `finishedDrawing()` // Deprecated
* `didFinish()`

Notifies the delegate when someone finishes a stroke in the view
Expand All @@ -67,38 +73,56 @@ Notifies the delegate when someone finishes a stroke in the view
The following sample code checks if there is a signature in the view before getting it.

```
class MyViewController: UIViewController, YPSignatureDelegate {
@IBOutlet weak var drawSignatureView: YPDrawSignatureView!
class ViewController: UIViewController, YPSignatureDelegate {
// Connect this Outlet to the Signature View
@IBOutlet weak var signatureView: YPDrawSignatureView!
override func viewDidLoad() {
super.viewDidLoad()
// Set self to YPDrawSignature View delegate
drawSignatureView.delegate = self
// Do any additional setup after loading the view, typically from a nib.
// Setting this view controller as the signature view delegate, so the didStart() and
// didFinish() methods below in the delegate section are called.
signatureView.delegate = self
}
@IBAction func save(sender: AnyObject) {
// Checking if the view actually contains a signature
if drawSignatureView.doesContainSignature {
let img = drawSignatureView.getCroppedSignature()
// Do something with img
} else {
// Alert the user or do something else
}
// Function for clearing the content of signature view
@IBAction func clearSignature(_ sender: UIButton) {
// This is how the signature gets cleared
self.signatureView.clear()
}
@IBAction func clear(sender: AnyObject) {
drawSignatureView.clear()
// Function for saving signature
@IBAction func saveSignature(_ sender: UIButton) {
// Getting the Signature Image from self.drawSignatureView using the method getSignature().
if let signatureImage = self.signatureView.getSignature(scale: 10) {
// Saving signatureImage from the line above to the Photo Roll.
// The first time you do this, the app asks for access to your pictures.
UIImageWriteToSavedPhotosAlbum(signatureImage, nil, nil, nil)
// Since the Signature is now saved to the Photo Roll, the View can be cleared anyway.
self.signatureView.clear()
}
}
// MARK: - Optional delegate methods
// MARK: - Delegate Methods
// The delegate functions gives feedback to the instanciating class. All functions are optional,
// meaning you just implement the one you need.
// didStart() is called right after the first touch is registered in the view.
// For example, this can be used if the view is embedded in a scroll view, temporary
// stopping it from scrolling while signing.
func didStart() {
// Do something when start drawing, like disable scrolling if view is embedded in an UIScrollView or UITableViewCell
print("Started Drawing")
}
// didFinish() is called rigth after the last touch of a gesture is registered in the view.
// Can be used to enabe scrolling in a scroll view if it has previous been disabled.
func didFinish() {
// Do something else when finished drawing, like enabling scrolling if YPDrawSignatureView is embedded in an UIScrollView or UITableViewCell
print("Finished Drawing")
}
}
```
Expand Down Expand Up @@ -132,8 +156,10 @@ YPDrawSignatureView is available under the MIT license. See the [LICENSE](LICENS

## Update history

### v1.0.2 - 5/3/17
### v1.1 - 5/3/17

* Added PDF support for exporting signature as high resolution vector graphics
* Deprecated methods and properties are properly marked
* Cleaning up method naming
* Delegate methods are now optional
* Sample project updated to latest settings
Expand Down
5 changes: 5 additions & 0 deletions SignatureTest/SignatureTest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
};
4BE489F81C252F8E00741EAD = {
CreatedOnToolsVersion = 7.2;
DevelopmentTeam = 784F7MSSDM;
LastSwiftMigration = 0800;
TestTargetID = 4BE489E41C252F8B00741EAD;
};
Expand Down Expand Up @@ -410,6 +411,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = SignatureTest/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = SignatureTest;
Expand All @@ -422,6 +424,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = SignatureTest/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = SignatureTest;
Expand All @@ -435,6 +438,7 @@
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
DEVELOPMENT_TEAM = 784F7MSSDM;
INFOPLIST_FILE = SignatureTestTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.yuppielabel.SignatureTestTests;
Expand All @@ -448,6 +452,7 @@
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
DEVELOPMENT_TEAM = 784F7MSSDM;
INFOPLIST_FILE = SignatureTestTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.yuppielabel.SignatureTestTests;
Expand Down
2 changes: 1 addition & 1 deletion SignatureTest/SignatureTest/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// YPDrawSignatureView is open source
// Version 1.0.2
// Version 1.1
//
// Copyright (c) 2014 - 2017 The YPDrawSignatureView Project Contributors
// Available under the MIT license
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down Expand Up @@ -30,6 +40,16 @@
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
Expand Down Expand Up @@ -59,6 +79,11 @@
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
}
],
"info" : {
Expand Down
16 changes: 12 additions & 4 deletions SignatureTest/SignatureTest/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11198.2" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12120" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -15,27 +18,32 @@
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="z9t-5y-AWr">
<rect key="frame" x="-12.5" y="168.5" width="400" height="330"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="u9Q-lu-sya" customClass="YPDrawSignatureView" customModule="SignatureTest" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="400" height="300"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="300" id="I4C-mE-4SQ"/>
<constraint firstAttribute="width" constant="400" id="Wtv-bb-sg2"/>
</constraints>
</view>
<stackView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="QC8-3Q-hSJ">
<rect key="frame" x="0.0" y="300" width="400" height="30"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="pPw-h6-9Q7">
<rect key="frame" x="0.0" y="0.0" width="200" height="30"/>
<state key="normal" title="Clear"/>
<connections>
<action selector="clearSignature:" destination="BYZ-38-t0r" eventType="touchUpInside" id="4az-lt-2Z1"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Zdh-YE-RA9">
<rect key="frame" x="200" y="0.0" width="200" height="30"/>
<state key="normal" title="Save signature"/>
<connections>
<action selector="saveSignature:" destination="BYZ-38-t0r" eventType="touchUpInside" id="LV0-XM-Gv2"/>
Expand Down
2 changes: 1 addition & 1 deletion SignatureTest/SignatureTest/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>1.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
4 changes: 1 addition & 3 deletions SignatureTest/SignatureTest/ViewController.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// YPDrawSignatureView is open source
// Version 1.0.2
// Version 1.1
//
// Copyright (c) 2014 - 2017 The YPDrawSignatureView Project Contributors
// Available under the MIT license
Expand Down Expand Up @@ -65,6 +65,4 @@ class ViewController: UIViewController, YPSignatureDelegate {
func didFinish() {
print("Finished Drawing")
}


}
Loading

0 comments on commit a415fae

Please sign in to comment.