DM_YPDrawSignatureView 1.1.3

DM_YPDrawSignatureView 1.1.3

Dominic Miller 维护。



  • GJNilsen

YPDrawSignatureView

Image of Swift Version Badge

用于捕获签名的简单类。

Swift 4

代码在与 Xcode 9 Beta 2 分发的 Swift 4 兼容,无需任何修改。示例应用需要更新项目设置,因为这是一项无需触摸代码的简单操作,因此将更新设置的任务留给示例应用的用户。

Swift 3

该类支持 Swift 3。该分支与旧版本不兼容,如果无法支持 Swift 3,请下载先前的发布版本。将不会更新旧版本。

  • 将支持 Swift 3.0
  • 不支持 Swift 2.3

使用方法

在您想要签名捕获字段的地方添加一个新的 UIView。将其类设置为 YPDrawSignatureView,并将其连接到 UIViewController 中的 @IBOutlet 属性。为了保存和清除签名,在您的视图控制器中添加两个按钮。将每个按钮连接到 @IBAction 函数。

ScreenShot

选择视图后,选择 IB 属性检查器面板来设置自定义值,或者在初始化签名视图时通过代码设置它们。

新特性

根据用户的需求,在PDF数据格式中增加了签名导出为矢量路径。

方法

  • clear()

清除签名

  • getSignature()

返回YPDrawSignatureView实例的边界内的签名

  • getCroppedSignature()

返回签名内边界的签名

  • getPDFSignature()以矢量路径PDF数据格式返回签名

属性

  • doesContainSignature: Bool

这是一个计算只读属性,当视图实际包含签名时返回 true

  • strokeWidth: CGFloat

设置签名笔触的宽度

  • strokeColor: UIColor

设置签名笔触的颜色

可选协议方法

  • didStart()

当视图开始绘制笔触时通知代理

  • didFinish()

当视图结束绘制笔触时通知代理

示例代码

以下示例代码在获取签名前检查视图内是否存在签名。

class ViewController: UIViewController, YPSignatureDelegate {
    
    // Connect this Outlet to the Signature View
    @IBOutlet weak var signatureView: YPDrawSignatureView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // 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
    }
    
    // Function for clearing the content of signature view
    @IBAction func clearSignature(_ sender: UIButton) {
        // This is how the signature gets cleared
        self.signatureView.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: - 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() {
        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() {
        print("Finished Drawing")
    }
}

示例项目

查看示例项目以获取有关如何保存签名以及如何清除签名视图的更多信息。

安装

将 YPDrawSignature.swift 添加到您的项目中

支持与问题

GitHub 问题主要用于提交错误报告和功能请求。有关支持相关问题和帮助,请使用 StackOverflow

原作者

Geert-Jan Nilsen Yuppielabel

贡献者

许可

YPDrawSignatureView 在 MIT 许可证下提供。有关更多信息,请参阅 LICENSE 文件。欢迎 fork 和修改。

更新历史

v1.1.3 - 3/30/18

  • 小错误修复。

v1.1.2 - 6/16/17

  • 小错误修复。

v1.1.1 - 5/23/17

  • 错误修复

v1.1 - 5/3/17

  • 增加了PDF支持,可以将签名导出为高分辨率矢量图形
  • 已弃用的方法和属性已被正确标记
  • 整理方法命名
  • 委派方法现在是可选的
  • 示例项目更新到最新设置

v1.0.1 - 5/2/17

  • 小错误修复

v1.0 - 9/12/16

  • 更多Swifty API
  • 支持 Swift 3