Skip to content

Commit

Permalink
Merge pull request #22 from GJNilsen/Swift-3
Browse files Browse the repository at this point in the history
YPDrawSignature 1.0
  • Loading branch information
GJ Nilsen authored Sep 12, 2016
2 parents ab13798 + eef235a commit 8a7cee5
Show file tree
Hide file tree
Showing 9 changed files with 266 additions and 212 deletions.
38 changes: 22 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

Simple class for capturing signatures.

Inspired by [Capture a Signature on iOS](https://www.altamiracorp.com/blog/employee-posts/capture-a-signature-on-ios) by Jason Harwig, and [Macheads101](https://www.youtube.com/user/macheads101), he has a great [tutorial](https://www.youtube.com/watch?v=8KV1o9hPF5E&list=UU7fIuG6L5EPc9Ijq2_BCmIg) on YouTube.
## Swift 3

## Swift 2.2

The class supports Swift 2.2
The class supports Swift 3.
This branch is not backwards compatible, please download the previous release if you can not support Swift 3. Legacy versions will not be updated anymore.

- Swift 3.0 will be supported
- Swift 2.3 will not be supported
Expand All @@ -21,21 +20,21 @@ With the view selected, choose the IB Attributes Inspector panel to set custom v

#### Methods

* `clearSignature()`
* `clear()`

This clears the view

* `getSignature()`

This returns the signature with the bounds of the view

* `getSignatureCropped()`
* `getCroppedSignature()`

This returns the signature with the bounds of the signature

#### Properties

* `containsSignature: Bool`
* `doesContainSignature: Bool`

This is a computed read-only property returning `true` if the view actually contains a signature

Expand All @@ -53,11 +52,11 @@ Sets the background UIColor of the view

#### Optional Protocol Methods

* `startedSignatureDrawing()`
* `startedDrawing()`

Notifies the delegate when someone starts a stroke in the view

* `finishedSignatureDrawing()`
* `finishedDrawing()`

Notifies the delegate when someone finishes a stroke in the view

Expand All @@ -66,7 +65,7 @@ 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, YPDrawSignatureViewDelegate {
class MyViewController: UIViewController, YPSignatureDelegate {
@IBOutlet weak var drawSignatureView: YPDrawSignatureView!
Expand All @@ -79,24 +78,24 @@ class MyViewController: UIViewController, YPDrawSignatureViewDelegate {
@IBAction func save(sender: AnyObject) {
// Checking if the view actually contains a signature
if drawSignatureView.containsSignature {
let img = drawSignatureView.getSignatureCropped()
if drawSignatureView.doesContainSignature {
let img = drawSignatureView.getCroppedSignature()
// Do something with img
} else {
// Alert the user or do something else
}
}
@IBAction func clear(sender: AnyObject) {
drawSignatureView.clearSignature()
drawSignatureView.clear()
}
// MARK: - Optional delegate methods
func startedSignatureDrawing() {
func startedDrawing() {
// Do something when start drawing
}
func finishedSignatureDrawing() {
func finishedDrawing() {
// Do something else when finished drawing
}
}
Expand All @@ -116,7 +115,7 @@ GitHub Issues are for filing bug reports and feature requests only. Use [StackOv

## Original Author

[Geert-Jan Nilsen](mailto:gj.nilsen@yuppielabel.com) [Yuppielabel](http://yuppielabel.com)
[Geert-Jan Nilsen](mailto:gj.nilsen@appfact.com) [Yuppielabel](http://yuppielabel.com)

## Contributors

Expand All @@ -127,3 +126,10 @@ GitHub Issues are for filing bug reports and feature requests only. Use [StackOv
## License

YPDrawSignatureView is available under the MIT license. See the [LICENSE](LICENSE) file for more info. Feel free to fork and modify.

## Update history

### v1.0 - 9/12/16

* More Swifty API
* Supports Swift 3
17 changes: 16 additions & 1 deletion SignatureTest/SignatureTest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,21 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0720;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = Yuppielabel;
TargetAttributes = {
4BE489E41C252F8B00741EAD = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
};
4BE489F81C252F8E00741EAD = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
TestTargetID = 4BE489E41C252F8B00741EAD;
};
4BE48A031C252F8F00741EAD = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
TestTargetID = 4BE489E41C252F8B00741EAD;
};
};
Expand Down Expand Up @@ -407,6 +410,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.yuppielabel.SignatureTest;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -418,6 +422,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.yuppielabel.SignatureTest;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -429,6 +435,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.yuppielabel.SignatureTestTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SignatureTest.app/SignatureTest";
};
name = Debug;
Expand All @@ -441,6 +448,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.yuppielabel.SignatureTestTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SignatureTest.app/SignatureTest";
};
name = Release;
Expand All @@ -452,6 +461,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.yuppielabel.SignatureTestUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_TARGET_NAME = SignatureTest;
USES_XCTRUNNER = YES;
};
Expand All @@ -464,6 +474,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.yuppielabel.SignatureTestUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
TEST_TARGET_NAME = SignatureTest;
USES_XCTRUNNER = YES;
};
Expand All @@ -488,6 +500,7 @@
4BE48A0F1C252F8F00741EAD /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
4BE48A101C252F8F00741EAD /* Build configuration list for PBXNativeTarget "SignatureTestTests" */ = {
isa = XCConfigurationList;
Expand All @@ -496,6 +509,7 @@
4BE48A121C252F8F00741EAD /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
4BE48A131C252F8F00741EAD /* Build configuration list for PBXNativeTarget "SignatureTestUITests" */ = {
isa = XCConfigurationList;
Expand All @@ -504,6 +518,7 @@
4BE48A151C252F8F00741EAD /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
78 changes: 40 additions & 38 deletions SignatureTest/SignatureTest/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
// YPDrawSignatureView is open source
// Version 1.0
//
// AppDelegate.swift
// SignatureTest
//
// Created by Geert-Jan Korsbø Nilsen on 19/12/15.
// Copyright © 2015 Yuppielabel. All rights reserved.
// Copyright (c) 2014 - 2016 Yuppielabel and the project contributors
// Available under the MIT license
//
// See https://github.com/yuppielabel/YPDrawSignatureView/blob/master/LICENSE for license information
// See https://github.com/yuppielabel/YPDrawSignatureView/blob/master/README.md for the list project contributors

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}



var window: UIWindow?

func applicationDidFinishLaunching(_ application: UIApplication) {

}

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
return true
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

27 changes: 9 additions & 18 deletions SignatureTest/SignatureTest/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<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">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand All @@ -14,40 +15,30 @@
<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="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<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="100" y="135" 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" white="1" alpha="1" colorSpace="calibratedWhite"/>
<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>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="color" keyPath="signatureBackgroundColor">
<color key="value" white="1" alpha="1" colorSpace="calibratedWhite"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</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="aBv-0K-dAa"/>
<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="3Lv-P3-mo6"/>
<action selector="saveSignature:" destination="BYZ-38-t0r" eventType="touchUpInside" id="LV0-XM-Gv2"/>
</connections>
</button>
</subviews>
Expand All @@ -58,14 +49,14 @@
</subviews>
</stackView>
</subviews>
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="0.66666666666666663" green="0.66666666666666663" blue="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="z9t-5y-AWr" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="lq8-Pw-rbn"/>
<constraint firstItem="z9t-5y-AWr" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" id="rvO-ps-USf"/>
</constraints>
</view>
<connections>
<outlet property="drawSignatureView" destination="u9Q-lu-sya" id="xhH-7O-Jem"/>
<outlet property="signatureView" destination="u9Q-lu-sya" id="Pst-Q1-2hh"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
Expand Down
2 changes: 2 additions & 0 deletions SignatureTest/SignatureTest/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPhotoLibraryUsageDescription</key>
<string>Needs this key set for saving to PhotoRoll</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
Expand Down
Loading

0 comments on commit 8a7cee5

Please sign in to comment.