SignatureView for SwiftUI
SignatureView
is a SwiftUI component that integrates PencilKit to provide a smooth and flexible signature drawing experience. Designed for iOS applications, it allows users to draw signatures with support for colors, stroke width customization, and image overlay.
Features
- ✍️ Draw and capture signatures using Apple Pencil or touch input.
- ? Customize signature stroke color and width.
- ? Overlay an image behind the signature pad.
- ? Clear the signature view with ease.
- ? Combine the signature and the background image.
- ? Export the combined signature as a UIImage or a Base64 encoded string.
Installation
To add SignatureView
to your SwiftUI project, simply copy the SignatureView.swift
file into your project directory.
Usage
Here is how you can add a SignatureView
to your SwiftUI view:
import SwiftUI
struct YourView: View {
var body: some View {
SignatureView()
}
}
Customization
You can customize the signature view by initializing it with different parameters:
SignatureView(color: .red, width: 5.0)
Handling Signature Data
You can access the drawn signature as a PKDrawing object or a Base64 encoded string, which can be used for storage or network transfer.
@State private var signatureView = SignatureView()
// Get PKDrawing
let drawing = signatureView.drawing
// Get Base64 String
let base64String = signatureView.combinedBase64()
Clearing the Signature
To clear the signature view:
signatureView.clear()
Overlaying an Image
To overlay an image behind the signature pad:
let imageData = UIImage(named: "your-background-image").pngData()
signatureView.setImage(with: imageData)
Contributing
Contributions are welcome! Please fork the repository and submit a pull request with your updates.
License
SignatureView is released under the MIT License. See LICENSE for details.
Contact
If you have any questions or suggestions, please open an issue on the GitHub repository page.
This README file is created with ❤️ by ChatGPT